##############################################
########summary stats#########################
##############################################

##Conditional Analysis##
stargazer(exprop_dem_gdp[c('democracy_p',
                           'leg_constraints', 'v2x_veracc', 'gdp_pc')],
          summary.stat = c("n", "mean", "sd", 'min', 'max'),
          title='Summary Statistics (Conditional Analysis)',
          covariate.labels=c('Democracy', 
                             'Legislative Constraints', 'Vertical Accountability',
                             'GDP per capita'))

##Panel Analysis###
stargazer(ex_full_panel[c( 'democracy_p',
                            'leg_constraints', 'v2x_veracc',
                            'gdp_pc', 'history')],
          summary.stat = c("n", "mean", "sd", 'min', 'max'),
          title='Summary Statistics (Panel Analysis)',
          covariate.labels=c('Democracy', 
                             'Legislative Constraints', 'Vertical Accountability',
                             'GDP Per Capita', 'Expropriation History'))


###################################################
##########Conditional LC Analysis without Intervention############
###################################################

m1_nint<-glm(strong_exprop~leg_constraints, data=exprop_dem_gdp, family='binomial', subset=type!='int')
cov.m1_nint <- vcovCL(m1_nint, ~country) 
robust.se.m1_nint <- sqrt(diag(cov.m1_nint))

m2_nint<-glm(strong_exprop~leg_constraints+democracy_p+ll_gdp_pc+ll_gdp_pc2+factor(sector2), data=exprop_dem_gdp, family='binomial', subset=type!='int')
cov.m2_nint <- vcovCL(m2_nint, ~country)
robust.se.m2_nint <- sqrt(diag(cov.m2_nint))

m3_nint<-glm(strong_exprop~leg_constraints+ll_gdp_pc+ll_gdp_pc2+factor(sector2)+region+factor(year_bin), data=exprop_dem_gdp, family='binomial', subset=type!='int')
cov.m3_nint <- vcovCL(m3_nint, ~country)
robust.se.m3_nint <- sqrt(diag(cov.m3_nint))

m4_nint<-glm(strong_exprop~leg_constraints+democracy_p+ll_gdp_pc+ll_gdp_pc2+factor(sector2)+region+factor(year_bin), data=exprop_dem_gdp, family='binomial', subset=type!='int')
cov.m4_nint <- vcovCL(m4_nint, ~country)
robust.se.m4_nint <- sqrt(diag(cov.m4_nint))

conditional_expropriation_nint_table<-stargazer(m1_nint, m2_nint, m3_nint, m4_nint, se=list(robust.se.m1_nint, robust.se.m2_nint, robust.se.m3_nint, robust.se.m4_nint),
                                                align=TRUE, omit=c('year_bin', 'region','Constant'), header=FALSE, label="table:conditional_expropriation_nint",
                                                covariate.labels=c("Legislative Constraints", "Democracy", "GDP per capita", "GDP per capita squared", "Extractive sector",
                                                                   "Financial sector", "Manufacturing sector", "Services sector", "Utilities sector"
                                                                   ), title="Legislative Constraints and Propensity to Use Overt Expropriation, Excluding Intervention (Logit Model)", font.size="footnotesize", column.sep.width="0pt",
                                                add.lines=list(c("Decade/Region FE", "N", "N", "Y","Y")),
                                                dep.var.labels="Use of overt (1) vs. covert (0) expropriation", no.space=TRUE,
                                                notes="Robust standard errors clustered at country level")
write(conditional_expropriation_nint_table[4:length(conditional_expropriation_nint_table)-1], 'R_analysis/PaperOutput/conditional_expropriation_nint_table.tex')


###################################################
##########Conditional Vert Acc without Intervention############
###################################################

m1_nint_ac<-glm(strong_exprop~v2x_veracc, data=exprop_dem_gdp, family='binomial', subset=type!='int')
cov.m1_nint_ac <- vcovCL(m1_nint_ac, ~country) 
robust.se.m1_nint_ac <- sqrt(diag(cov.m1_nint_ac))

m2_nint_ac<-glm(strong_exprop~v2x_veracc+democracy_p+ll_gdp_pc+ll_gdp_pc2+factor(sector2), data=exprop_dem_gdp, family='binomial', subset=type!='int')
cov.m2_nint_ac <- vcovCL(m2_nint_ac, ~country)
robust.se.m2_nint_ac <- sqrt(diag(cov.m2_nint_ac))

m3_nint_ac<-glm(strong_exprop~v2x_veracc+ll_gdp_pc+ll_gdp_pc2+factor(sector2)+region+factor(year_bin), data=exprop_dem_gdp, family='binomial', subset=type!='int')
cov.m3_nint_ac <- vcovCL(m3_nint_ac, ~country)
robust.se.m3_nint_ac <- sqrt(diag(cov.m3_nint_ac))

m4_nint_ac<-glm(strong_exprop~v2x_veracc+democracy_p+ll_gdp_pc+ll_gdp_pc2+factor(sector2)+region+factor(year_bin), data=exprop_dem_gdp, family='binomial', subset=type!='int')
cov.m4_nint_ac <- vcovCL(m4_nint_ac, ~country)
robust.se.m4_nint_ac <- sqrt(diag(cov.m4_nint_ac))

conditional_expropriation_nint_table_ac<-stargazer(m1_nint_ac, m2_nint_ac, m3_nint_ac, m4_nint_ac, se=list(robust.se.m1_nint_ac, robust.se.m2_nint_ac, robust.se.m3_nint_ac, robust.se.m4_nint_ac),
                                                align=TRUE, omit=c('year_bin', 'region','Constant'), header=FALSE, label="table:conditional_expropriation_ac",
                                                covariate.labels=c("Vertical Accountability", "Democracy", "GDP per capita", "GDP per capita squared", "Extractive sector",
                                                                   "Financial sector", "Manufacturing sector", "Services sector", "Utilities sector"
                                                                   ), title="Vertical Accountability and Propensity to Use Overt Expropriation (Logit Model)", font.size="footnotesize", column.sep.width="0pt",
                                                add.lines=list(c("Decade/Region FE", "N", "N", "Y","Y")),
                                                dep.var.labels="Use of overt (1) vs. covert (0) expropriation", no.space=TRUE,
                                                notes="Robust standard errors clustered at country level")
write(conditional_expropriation_nint_table_ac[4:length(conditional_expropriation_nint_table_ac)-1], 'R_analysis/PaperOutput/conditional_expropriation_nint_table_ac.tex')










#############################################################################
#######multinomial logit diff coding when overt+covert same year################
#############################################################################

ex_full_panel$exprop_numeric_diff<-NA
ex_full_panel$exprop_numeric_diff[ex_full_panel$exprop_numeric==0]<-0
ex_full_panel$exprop_numeric_diff[ex_full_panel$num_strong_exprop>0]<-2
ex_full_panel$exprop_numeric_diff[ex_full_panel$num_weak_exprop>0]<-1

ex_full_panel$exprop_numeric_diff_b1<-NA
ex_full_panel$exprop_numeric_diff_b1[ex_full_panel$exprop_numeric==0]<-1
ex_full_panel$exprop_numeric_diff_b1[ex_full_panel$exprop_numeric ==1]<-0
ex_full_panel$exprop_numeric_diff_b1[ex_full_panel$exprop_numeric ==2]<-2


##legislative constraints no controls
lc_nc_diff_df<-multinom_function(ex_full_panel[c('exprop_numeric_diff', 'exprop_numeric_diff_b1', 'leg_constraints', 'country_num')], 'exprop_numeric_diff', 'exprop_numeric_diff_b1', iterations)
ggsave('R_analysis/PaperOutput/lc_multinom_nocontrols_diff_plot.pdf', plot=multinom_plot(lc_nc_diff_df), height=5, width=5.25)


#legislative constraints full controls
lc_fc_diff_df<-multinom_function(ex_full_panel[c('exprop_numeric_diff', 'exprop_numeric_diff_b1', 'leg_constraints','year_bin', 'democracy_p',
                                                   'll_gdp_pc', 'll_gdp_pc2', 'history', 'region', 'country_num')], 'exprop_numeric_diff', 'exprop_numeric_diff_b1', iterations)
ggsave('R_analysis/PaperOutput/lc_multinom_fullcontrols_diff_plot.pdf', plot=multinom_plot(lc_fc_diff_df), height=5, width=5.25)


##vertical accountability

ac_nc_diff_df<-multinom_function(ex_full_panel[c('exprop_numeric_diff', 'exprop_numeric_diff_b1', 'v2x_veracc', 'country_num')], 'exprop_numeric_diff', 'exprop_numeric_diff_b1', iterations)
ggsave('R_analysis/PaperOutput/ac_multinom_nocontrols_diff_plot.pdf', plot=multinom_plot(ac_nc_diff_df), height=5, width=5.25)


#full controls
ac_fc_diff_df<-multinom_function(ex_full_panel[c('exprop_numeric_diff', 'exprop_numeric_diff_b1', 'v2x_veracc','year_bin', 'democracy_p',
                                                    'll_gdp_pc', 'll_gdp_pc2', 'history', 'region', 'country_num')], 'exprop_numeric_diff', 'exprop_numeric_diff_b1', iterations)
ggsave('R_analysis/PaperOutput/ac_multinom_fullcontrols_diff_plot.pdf', plot=multinom_plot(ac_fc_diff_df), height=5, width=5.25)



#############################################################################
#######Alternate Panel Constructions (FDI Stock and only Kobrin)################
#############################################################################

################################
###FDI Stock only##################
################################

fdi_stock_panel $exprop_numeric_b1<-NA
fdi_stock_panel $exprop_numeric_b1[fdi_stock_panel $exprop_numeric==1]<-0
fdi_stock_panel $exprop_numeric_b1[fdi_stock_panel $exprop_numeric==0]<-1
fdi_stock_panel $exprop_numeric_b1[fdi_stock_panel $exprop_numeric==2]<-2
fdi_stock_panel $country_num<-as.numeric(as.factor(fdi_stock_panel $country))
fdi_stock_panel $ll_gdp_pc<-log(fdi_stock_panel $lag_gdp_pc)
fdi_stock_panel $ll_gdp_pc2<-log(fdi_stock_panel $lag_gdp_pc)^2

fdi_stock_panel$year_bin<-NA
fdi_stock_panel$year_bin[fdi_stock_panel$year>=1960&fdi_stock_panel$year<1970]<-"1960s"
fdi_stock_panel$year_bin[fdi_stock_panel$year>1969&fdi_stock_panel$year<1980]<-"1970s"
fdi_stock_panel$year_bin[fdi_stock_panel$year>1979&fdi_stock_panel$year<1990]<-"1980s"
fdi_stock_panel$year_bin[fdi_stock_panel$year>1989&fdi_stock_panel$year<2000]<-"1990s"
fdi_stock_panel$year_bin[fdi_stock_panel$year>1999&fdi_stock_panel$year<2010]<-"2000s"
fdi_stock_panel$year_bin[fdi_stock_panel$year>2009]<-"2010s"

##Legislative constraints##
m1_fdi_stock_panel_all_fdi_stock<-lm(num_exprop~ leg_constraints+democracy_p +log(lag_gdp_pc)+I(log(lag_gdp_pc)^2)+history+region+year_bin, data= fdi_stock_panel)
m1_fdi_stock_panel_all_se_fdi_stock<-sqrt(diag(vcovCluster(m1_fdi_stock_panel_all_fdi_stock, fdi_stock_panel $country[is.na(fdi_stock_panel $democracy_p)==FALSE&is.na(fdi_stock_panel $leg_constraints)==FALSE&is.na(fdi_stock_panel $num_exprop)==FALSE])))

m1_fdi_stock_panel_strong_fdi_stock<-lm(num_strong_exprop~ leg_constraints+democracy_p +log(lag_gdp_pc)+I(log(lag_gdp_pc)^2)+history+region+year_bin, data= fdi_stock_panel)
m1_fdi_stock_panel_strong_se_fdi_stock<-sqrt(diag(vcovCluster(m1_fdi_stock_panel_strong_fdi_stock, fdi_stock_panel $country[is.na(fdi_stock_panel $democracy_p)==FALSE&is.na(fdi_stock_panel $leg_constraints)==FALSE&is.na(fdi_stock_panel $num_strong_exprop)==FALSE])))

m1_fdi_stock_panel_weak_fdi_stock<-lm(num_weak_exprop~ leg_constraints+democracy_p +log(lag_gdp_pc)+I(log(lag_gdp_pc)^2)+history+region+year_bin, data= fdi_stock_panel)
m1_fdi_stock_panel_weak_se_fdi_stock<-sqrt(diag(vcovCluster(m1_fdi_stock_panel_weak_fdi_stock, fdi_stock_panel $country[is.na(fdi_stock_panel $democracy_p)==FALSE&is.na(fdi_stock_panel $leg_constraints)==FALSE&is.na(fdi_stock_panel $num_weak_exprop)==FALSE])))

ols_fdistock_panel<-stargazer(m1_fdi_stock_panel_all_fdi_stock, m1_fdi_stock_panel_strong_fdi_stock, m1_fdi_stock_panel_weak_fdi_stock, 
                               se=list(m1_fdi_stock_panel_all_se_fdi_stock, m1_fdi_stock_panel_strong_se_fdi_stock, m1_fdi_stock_panel_weak_se_fdi_stock),
                               align=TRUE, omit=c('year_bin', 'region','Constant'), header=FALSE, label="table:ols_fdipanel_panel",
                               covariate.labels=c("Legislative Constraints", "Democracy", "GDP per capita", "GDP per capita squared", "Expropriation History"), title="Legislative Constraints and expropriation type, panel with FDI stock using OLS", font.size="footnotesize", column.sep.width="15pt",
                               add.lines=list(c("Decade/Region FE", "Y", "Y", "Y")),
                              omit.stat=c("f", "ser"),dep.var.caption  = "DV: Number of expropriations in given year",
                              dep.var.labels=c("Any expropriation","Overt expropriation","Covert expropriation"), no.space=TRUE,
                               notes = "Robust standard errors clustered at the country level")

write(ols_fdistock_panel, 'R_analysis/PaperOutput/ols_fdistock_panel.tex')

#No controls LC
nc_lc_fdistock<-multinom_function(fdi_stock_panel[c('exprop_numeric', 'exprop_numeric_b1', 'leg_constraints', 'country_num')], 'exprop_numeric', 'exprop_numeric_b1', iterations)
write.csv(nc_lc_fdistock, 'nc_lc_fdistock.csv')
ggsave('R_analysis/PaperOutput/multinom_nocontrols_lc_fdistock.pdf', plot=multinom_plot(nc_lc_fdistock), height=5, width=5.25)


#full LC controls with decade FEs
multinom_controls_fdipanel_decade_fes<-multinom_function(fdi_stock_panel[c('exprop_numeric', 'exprop_numeric_b1', 'leg_constraints','year_bin', 'democracy_p',
                                                                'll_gdp_pc', 'll_gdp_pc2', 'history', 'region', 'country_num')], 'exprop_numeric', 'exprop_numeric_b1', iterations)
ggsave('R_analysis/PaperOutput/multinom_fullcontrols_fdistock_decade_fes_plot.pdf', plot=multinom_plot(multinom_controls_fdipanel_decade_fes), height=5, width=5.25)






##Vertical Accountability##
m1_fdi_stock_panel_all_fdi_stock_ac<-lm(num_exprop~ v2x_veracc+democracy_p +log(lag_gdp_pc)+I(log(lag_gdp_pc)^2)+history+region+year_bin, data= fdi_stock_panel)
m1_fdi_stock_panel_all_se_fdi_stock_ac<-sqrt(diag(vcovCluster(m1_fdi_stock_panel_all_fdi_stock_ac, fdi_stock_panel $country[is.na(fdi_stock_panel $democracy_p)==FALSE&is.na(fdi_stock_panel $v2x_veracc)==FALSE&is.na(fdi_stock_panel $num_exprop)==FALSE])))

m1_fdi_stock_panel_strong_fdi_stock_ac<-lm(num_strong_exprop~ v2x_veracc+democracy_p +log(lag_gdp_pc)+I(log(lag_gdp_pc)^2)+history+region+year_bin, data= fdi_stock_panel)
m1_fdi_stock_panel_strong_se_fdi_stock_ac<-sqrt(diag(vcovCluster(m1_fdi_stock_panel_strong_fdi_stock_ac, fdi_stock_panel $country[is.na(fdi_stock_panel $democracy_p)==FALSE&is.na(fdi_stock_panel $v2x_veracc)==FALSE&is.na(fdi_stock_panel $num_strong_exprop)==FALSE])))

m1_fdi_stock_panel_weak_fdi_stock_ac<-lm(num_weak_exprop~ v2x_veracc+democracy_p +log(lag_gdp_pc)+I(log(lag_gdp_pc)^2)+history+region+year_bin, data= fdi_stock_panel)
m1_fdi_stock_panel_weak_se_fdi_stock_ac<-sqrt(diag(vcovCluster(m1_fdi_stock_panel_weak_fdi_stock_ac, fdi_stock_panel $country[is.na(fdi_stock_panel $democracy_p)==FALSE&is.na(fdi_stock_panel $v2x_veracc)==FALSE&is.na(fdi_stock_panel $num_weak_exprop)==FALSE])))

ols_fdistock_panel_ac<-stargazer(m1_fdi_stock_panel_all_fdi_stock_ac, m1_fdi_stock_panel_strong_fdi_stock_ac, m1_fdi_stock_panel_weak_fdi_stock_ac, 
                              se=list(m1_fdi_stock_panel_all_se_fdi_stock_ac, m1_fdi_stock_panel_strong_se_fdi_stock_ac, m1_fdi_stock_panel_weak_se_fdi_stock_ac),
                              align=TRUE, omit=c('year_bin', 'region','Constant'), header=FALSE, label="table:ols_fdipanel_panel_ac",
                              covariate.labels=c("Vertical Accountability", "Democracy", "GDP per capita", "GDP per capita squared", "Expropriation History"
                                                 ), title="Vertical Accountability and expropriation type, panel with FDI stock using OLS", font.size="footnotesize", column.sep.width="15pt",
                              add.lines=list(c("Decade/Region FE", "Y", "Y", "Y")),
                              omit.stat=c("f", "ser"),dep.var.caption  = "DV: Number of expropriations in given year",
                              dep.var.labels=c("Any expropriation","Overt expropriation","Covert expropriation"), no.space=TRUE,
                              notes = "Robust standard errors clustered at the country level")

write(ols_fdistock_panel_ac, 'R_analysis/PaperOutput/ols_fdistock_panel_ac.tex')


#no controls

multinom_nocontrols_fdipanel_ac<-
  multinom_function(fdi_stock_panel[c('exprop_numeric', 'exprop_numeric_b1', 
                                      'v2x_veracc', 'country_num')], 
                    'exprop_numeric', 'exprop_numeric_b1', iterations)
ggsave('R_analysis/PaperOutput/multinom_nocontrols_fdistock_plot_ac.pdf', 
       plot=multinom_plot(multinom_nocontrols_fdipanel_ac), height=5, width=5.25)


#full controls with decade fes
multinom_controls_fdipanel_decade_fes_ac<-
  multinom_function(fdi_stock_panel[c('exprop_numeric', 
                                      'exprop_numeric_b1', 'v2x_veracc', 'year_bin',
                                      'democracy_p','ll_gdp_pc', 'll_gdp_pc2', 
                                      'history', 'region', 'country_num')], 
                    'exprop_numeric', 'exprop_numeric_b1', iterations)
ggsave('R_analysis/PaperOutput/multinom_fullcontrols_fdistock_decade_fes_plot_ac.pdf', 
       plot=multinom_plot(multinom_controls_fdipanel_decade_fes_ac), height=5, width=5.25)

################################
####Kobrin only################
################################

ex_kobrin_panel$exprop_numeric_b1<-NA
ex_kobrin_panel$exprop_numeric_b1[ex_kobrin_panel$exprop_numeric==1]<-0
ex_kobrin_panel$exprop_numeric_b1[ex_kobrin_panel$exprop_numeric==0]<-1
ex_kobrin_panel$exprop_numeric_b1[ex_kobrin_panel$exprop_numeric==2]<-2
ex_kobrin_panel$country_num<-as.numeric(as.factor(ex_kobrin_panel$country))
ex_kobrin_panel $ll_gdp_pc<-log(ex_kobrin_panel $lag_gdp_pc)
ex_kobrin_panel $ll_gdp_pc2<-log(ex_kobrin_panel $lag_gdp_pc)^2


##################Legislative constraints, OLS################

m1_kobrin_panel_all_kobrin<-lm(num_exprop~ leg_constraints+democracy_p +log(lag_gdp_pc)+I(log(lag_gdp_pc)^2)+history+region+year_bin, data= ex_kobrin_panel)
m1_kobrin_panel_all_se_kobrin<-sqrt(diag(vcovCluster(m1_kobrin_panel_all_kobrin, ex_kobrin_panel $country[is.na(ex_kobrin_panel $democracy_p)==FALSE&is.na(ex_kobrin_panel$leg_constraints)==FALSE])))

m1_kobrin_panel_strong_kobrin<-lm(num_strong_exprop~ leg_constraints+democracy_p +log(lag_gdp_pc)+I(log(lag_gdp_pc)^2)+history+region+year_bin, data= ex_kobrin_panel)
m1_kobrin_panel_strong_se_kobrin<-sqrt(diag(vcovCluster(m1_kobrin_panel_strong_kobrin, ex_kobrin_panel $country[is.na(ex_kobrin_panel $democracy_p)==FALSE&is.na(ex_kobrin_panel$leg_constraints)==FALSE])))

m1_kobrin_panel_weak_kobrin<-lm(num_weak_exprop~ leg_constraints+democracy_p +log(lag_gdp_pc)+I(log(lag_gdp_pc)^2)+history+region+year_bin, data= ex_kobrin_panel)
m1_kobrin_panel_weak_se_kobrin<-sqrt(diag(vcovCluster(m1_kobrin_panel_weak_kobrin, ex_kobrin_panel $country[is.na(ex_kobrin_panel $democracy_p)==FALSE&is.na(ex_kobrin_panel$leg_constraints)==FALSE])))

ols_kobrin_panel<-stargazer(m1_kobrin_panel_all_kobrin, m1_kobrin_panel_strong_kobrin, m1_kobrin_panel_weak_kobrin, 
                            se=list(m1_kobrin_panel_all_se_kobrin, m1_kobrin_panel_strong_se_kobrin, m1_kobrin_panel_weak_se_kobrin),
                            align=TRUE, omit=c('year_bin', 'region','Constant'), header=FALSE, label="table:ols_kobrin_panel",
                            covariate.labels=c("Legislative Constraints", "Democracy", "GDP per capita", "GDP per capita squared", "Expropriation History"
                                               ), title="Legislative constraints and propensity to use overt expropriation, panel (only Kobrin countries) using OLS", font.size="footnotesize", column.sep.width="15pt",
                            add.lines=list(c("Decade/Region FE", "Y", "Y", "Y")),
                            omit.stat=c("f", "ser"),dep.var.caption  = "DV: Number of expropriations in given year",
                            dep.var.labels=c("Any expropriation","Overt expropriation","Covert expropriation"), no.space=TRUE,
                            notes = "Robust standard errors clustered at the country level")

write(ols_kobrin_panel, 'R_analysis/PaperOutput/ols_kobrin_panel.tex')

##################Legislative constraints, multinomial logit################


multinom_nocontrols_kobrin<-multinom_function(ex_kobrin_panel[c('exprop_numeric', 'exprop_numeric_b1', 'leg_constraints', 'country_num')], 'exprop_numeric', 'exprop_numeric_b1', iterations)
ggsave('R_analysis/PaperOutput/multinom_nocontrols_kobrinpanel_plot.pdf', plot=multinom_plot(multinom_nocontrols_kobrin), height=5, width=5.25)


#full controls
multinom_controls_kobrin<-multinom_function(ex_kobrin_panel[c('exprop_numeric', 'exprop_numeric_b1','leg_constraints','year_bin',  'democracy_p',
                                                              'll_gdp_pc', 'll_gdp_pc2', 'history', 'region', 'country_num')], 'exprop_numeric', 'exprop_numeric_b1', iterations)
ggsave('R_analysis/PaperOutput/multinom_fullcontrols_kobrinpanel_plot.pdf', plot=multinom_plot(multinom_controls_kobrin), height=5, width=5.25)


################Vertical acountability OLS################
m1_kobrin_panel_all_kobrin_ac<-lm(num_exprop~ v2x_veracc+democracy_p +log(lag_gdp_pc)+I(log(lag_gdp_pc)^2)+history+region+year_bin, data= ex_kobrin_panel)
m1_kobrin_panel_all_se_kobrin_ac<-sqrt(diag(vcovCluster(m1_kobrin_panel_all_kobrin_ac, ex_kobrin_panel $country[is.na(ex_kobrin_panel $democracy_p)==FALSE&is.na(ex_kobrin_panel$v2x_veracc)==FALSE])))

m1_kobrin_panel_strong_kobrin_ac<-lm(num_strong_exprop~ v2x_veracc+democracy_p +log(lag_gdp_pc)+I(log(lag_gdp_pc)^2)+history+region+year_bin, data= ex_kobrin_panel)
m1_kobrin_panel_strong_se_kobrin_ac<-sqrt(diag(vcovCluster(m1_kobrin_panel_strong_kobrin_ac, ex_kobrin_panel $country[is.na(ex_kobrin_panel $democracy_p)==FALSE&is.na(ex_kobrin_panel$v2x_veracc)==FALSE])))

m1_kobrin_panel_weak_kobrin_ac<-lm(num_weak_exprop~ v2x_veracc+democracy_p +log(lag_gdp_pc)+I(log(lag_gdp_pc)^2)+history+region+year_bin, data= ex_kobrin_panel)
m1_kobrin_panel_weak_se_kobrin_ac<-sqrt(diag(vcovCluster(m1_kobrin_panel_weak_kobrin_ac, ex_kobrin_panel $country[is.na(ex_kobrin_panel $democracy_p)==FALSE&is.na(ex_kobrin_panel$v2x_veracc)==FALSE])))

ols_kobrin_panel_ac<-stargazer(m1_kobrin_panel_all_kobrin_ac, m1_kobrin_panel_strong_kobrin_ac, m1_kobrin_panel_weak_kobrin_ac, 
                            se=list(m1_kobrin_panel_all_se_kobrin_ac, m1_kobrin_panel_strong_se_kobrin_ac, m1_kobrin_panel_weak_se_kobrin_ac),
                            align=TRUE, omit=c('year_bin', 'region','Constant'), header=FALSE, label="table:ols_kobrin_panel",
                            covariate.labels=c("Vertical Accountability", "Democracy", "GDP per capita", "GDP per capita squared", "Expropriation History"
                                               ), title="Vertical Accountability and propensity to use overt expropriation, panel (only Kobrin countries) using OLS", font.size="footnotesize", column.sep.width="15pt",
                            add.lines=list(c("Decade/Region FE", "Y", "Y", "Y")),
                            omit.stat=c("f", "ser"),dep.var.caption  = "DV: Number of expropriations in given year",
                            dep.var.labels=c("Any expropriation","Overt expropriation","Covert expropriation"), no.space=TRUE,
                            notes = "Robust standard errors clustered at the country level")

write(ols_kobrin_panel_ac, 'R_analysis/PaperOutput/ols_kobrin_panel_ac.tex')


################Vertical acountability multinomial logit################

multinom_nocontrols_kobrin_ac<-multinom_function(ex_kobrin_panel[c('exprop_numeric', 'exprop_numeric_b1', 'v2x_veracc', 'country_num')], 'exprop_numeric', 'exprop_numeric_b1', iterations)
ggsave('R_analysis/PaperOutput/multinom_nocontrols_kobrinpanel_plot_ac.pdf', plot=multinom_plot(multinom_nocontrols_kobrin_ac), height=5, width=5.25)


#full controls
multinom_controls_kobrin_ac<-multinom_function(ex_kobrin_panel[c('exprop_numeric', 'exprop_numeric_b1','v2x_veracc','year_bin',  'democracy_p',
                                                              'll_gdp_pc', 'll_gdp_pc2', 'history', 'region', 'country_num')], 'exprop_numeric', 'exprop_numeric_b1', iterations)
ggsave('R_analysis/PaperOutput/multinom_fullcontrols_kobrinpanel_plot_ac.pdf', plot=multinom_plot(multinom_controls_kobrin_ac), height=5, width=5.25)

#####################################################################################
##############Alternative Leg constraints ##################################
#####################################################################################


###################################################
############## Original VDem coding #################
###################################################
m1_leg_orig<-glm(strong_exprop~v2xlg_legcon, data=exprop_dem_gdp, family='binomial')
cov.m1_leg_orig_cluster <- vcovCL(m1_leg_orig, ~country)
robust.se.m1_leg_orig_cluster <- sqrt(diag(cov.m1_leg_orig_cluster))

m2_leg_orig<-glm(strong_exprop~v2xlg_legcon+democracy_p+log(lag_gdp_pc)+I(log(lag_gdp_pc)^2)+factor(sector2), data=exprop_dem_gdp, family='binomial')
cov.m2_leg_orig_cluster <- vcovCL(m2_leg_orig, ~country)
robust.se.m2_leg_orig_cluster <- sqrt(diag(cov.m2_leg_orig_cluster))

m3_leg_orig<-glm(strong_exprop~v2xlg_legcon+log(lag_gdp_pc)+I(log(lag_gdp_pc)^2)+factor(sector2)+region+factor(year_bin), data=exprop_dem_gdp, family='binomial')
cov.m3_leg_orig_cluster <- vcovCL(m3_leg_orig, ~country)
robust.se.m3_leg_orig_cluster <- sqrt(diag(cov.m3_leg_orig_cluster))

m4_leg_orig<-glm(strong_exprop~v2xlg_legcon+democracy_p+log(lag_gdp_pc)+I(log(lag_gdp_pc)^2)+factor(sector2)+region+factor(year_bin), data=exprop_dem_gdp, family='binomial')
cov.m4_leg_orig_cluster <- vcovCL(m4_leg_orig, ~country)
robust.se.m4_leg_orig_cluster <- sqrt(diag(cov.m4_leg_orig_cluster))

original_vdem_cluster<-stargazer(m1_leg_orig, m2_leg_orig, m3_leg_orig, m4_leg_orig, se=list(robust.se.m1_leg_orig_cluster, robust.se.m2_leg_orig_cluster, robust.se.m3_leg_orig_cluster, robust.se.m4_leg_orig_cluster),
                                 align=TRUE, omit=c('year_bin', 'region','Constant'), header=FALSE, label="table:conditional_expropriation_vdem_orig",
                                 covariate.labels=c("Legislative constraints", "Democracy","GDP per capita", "GDP per capita squared", "Extractive sector",
                                                    "Financial sector", "Manufacturing sector", "Services sector", "Utilities sector"
                                                    ), title="Propensity to Use Overt Expropriation (original VDem coding)", font.size="footnotesize", column.sep.width="0pt",
                                 add.lines=list(c("Decade/Region FE", "N", "N", "Y","Y")),
                                 dep.var.labels = "Use of overt (1) vs. covert (0) expropriation", no.space=TRUE,
                                 notes="Robust standard errors clustered at country level")
write(original_vdem_cluster, 'R_analysis/PaperOutput/original_vdem_cluster.tex')


##################Original vdem coding, OLS################
m1_panel_lc_all_alt_vdem<-lm(num_exprop~v2xlg_legcon+democracy_p+log(lag_gdp_pc)+I(log(lag_gdp_pc)^2)+history+region, data=ex_full_panel)
m1_panel_lc_all_se_alt_vdem<-sqrt(diag(vcovCluster(m1_panel_lc_all_alt_vdem, ex_full_panel$country[is.na(ex_full_panel$democracy_p)==FALSE&is.na(ex_full_panel$v2xlg_legcon)==FALSE&is.na(ex_full_panel$num_exprop)==FALSE])))

m1_panel_lc_strong_alt_vdem<-lm(num_strong_exprop~v2xlg_legcon+democracy_p+log(lag_gdp_pc)+I(log(lag_gdp_pc)^2)+history+region, data=ex_full_panel)
m1_panel_lc_strong_se_alt_vdem<-sqrt(diag(vcovCluster(m1_panel_lc_strong_alt_vdem, ex_full_panel$country[is.na(ex_full_panel$democracy_p)==FALSE&is.na(ex_full_panel$v2xlg_legcon)==FALSE&is.na(ex_full_panel$num_strong_exprop)==FALSE])))

m1_panel_lc_weak_alt_vdem<-lm(num_weak_exprop~v2xlg_legcon+democracy_p+log(lag_gdp_pc)+I(log(lag_gdp_pc)^2)+history+region, data=ex_full_panel)
m1_panel_lc_weak_se_alt_vdem<-sqrt(diag(vcovCluster(m1_panel_lc_weak_alt_vdem, ex_full_panel$country[is.na(ex_full_panel$democracy_p)==FALSE&is.na(ex_full_panel$v2xlg_legcon)==FALSE&is.na(ex_full_panel$num_weak_exprop)==FALSE])))

ols_panel_lc_alt_vdem<-stargazer(m1_panel_lc_all_alt_vdem, m1_panel_lc_strong_alt_vdem, m1_panel_lc_weak_alt_vdem, 
                        se=list(m1_panel_lc_all_se_alt_vdem, m1_panel_lc_strong_se_alt_vdem, m1_panel_lc_weak_se_alt_vdem),
                        align=TRUE, omit=c('year', 'region'), header=FALSE, label="table:ols_lc",
                        covariate.labels=c("Legislative Constraints", "Democracy", "GDP per capita", "GDP per capita squared", "Expropriation History",
                                           "Constant"), title="Legislative constraints and likelihood of using different types of expropriation, OLS panel (original VDem coding)", font.size="footnotesize", column.sep.width="15pt",
                        add.lines=list(c("Region FE", "Y", "Y", "Y")),
                        omit.stat=c("f", "ser"),dep.var.caption  = "DV: Number of expropriations in given year",
                        dep.var.labels=c("Any expropriation","Overt expropriation","Covert expropriation"), no.space=TRUE,
                        notes = "Robust standard errors clustered at the country level")

write(ols_panel_lc_alt_vdem, 'R_analysis/PaperOutput/ols_panel_lc_alt_vdem.tex')


##################Original vdem coding, multinomial logit################

#no controls
nc_lc_df_alt_vdem<-multinom_function(ex_full_panel[c('exprop_numeric', 'exprop_numeric_b1', 'v2xlg_legcon', 'country_num')], 'exprop_numeric', 'exprop_numeric_b1', iterations)
ggsave('R_analysis/PaperOutput/multinom_nocontrols_lc_plot_alt_vdem.pdf', plot=multinom_plot(nc_lc_df_alt_vdem), height=5, width=5.25)


#full controls
fc_lc_df_alt_vdem<-multinom_function(ex_full_panel[c('exprop_numeric', 'exprop_numeric_b1','v2xlg_legcon','year_bin', 'democracy_p', 
                                            'll_gdp_pc', 'll_gdp_pc2', 'history', 'region', 'country_num')], 'exprop_numeric', 'exprop_numeric_b1', iterations)
ggsave('R_analysis/PaperOutput/multinom_fullcontrols_lc_alt_vdem_plot.pdf', plot=multinom_plot(fc_lc_df_alt_vdem), height=5, width=5.25)



#################################################
########Henisz conditional###################
################################################

m1_polconv<-glm(strong_exprop~polconv, data=exprop_dem_gdp, family='binomial')
cov.m1_polconv_cluster <- vcovCL(m1_polconv, ~country)
robust.se.m1_polconv_cluster <- sqrt(diag(cov.m1_polconv_cluster))

m2_polconv<-glm(strong_exprop~polconv+democracy_p+ll_gdp_pc+ll_gdp_pc2+factor(sector2), data=exprop_dem_gdp, family='binomial')
cov.m2_polconv_cluster <- vcovCL(m2_polconv, ~country)
robust.se.m2_polconv_cluster <- sqrt(diag(cov.m2_polconv_cluster))

m3_polconv<-glm(strong_exprop~polconv+ll_gdp_pc+ll_gdp_pc2+factor(sector2)+region+factor(year_bin), data=exprop_dem_gdp, family='binomial')
cov.m3_polconv_cluster <- vcovCL(m3_polconv, ~country)
robust.se.m3_polconv_cluster <- sqrt(diag(cov.m3_polconv_cluster))

m4_polconv<-glm(strong_exprop~polconv+democracy_p+ll_gdp_pc+ll_gdp_pc2+factor(sector2)+region+factor(year_bin), data=exprop_dem_gdp, family='binomial')
cov.m4_polconv_cluster <- vcovCL(m4_polconv, ~country)
robust.se.m4_polconv_cluster <- sqrt(diag(cov.m4_polconv_cluster))

conditional_expropriation_polconv_table_cluster<-stargazer(m1_polconv, m2_polconv, m3_polconv, m4_polconv, se=list(robust.se.m1_polconv_cluster, robust.se.m2_polconv_cluster, robust.se.m3_polconv_cluster, robust.se.m4_polconv_cluster),
                                                           align=TRUE, omit=c('year_bin', 'region','Constant'), header=FALSE, label="table:conditional_expropriation_polconv",
                                                           covariate.labels=c("Political Constraints", "Democracy", "GDP per capita", "GDP per capita squared", "Extractive sector",
                                                                              "Financial sector", "Manufacturing sector", "Services sector", "Utilities sector"
                                                                              ), title="Overt expropriation and Henisz political constraints", font.size="footnotesize", column.sep.width="0pt",
                                                           add.lines=list(c("Decade/Region FE", "N", "N", "Y","Y")),
                                                           dep.var.labels = "Use of overt (1) vs. covert (0) expropriation", no.space=TRUE,
                                                           notes="Robust standard errors clustered at country level")
write(conditional_expropriation_polconv_table_cluster[4:length(conditional_expropriation_polconv_table_cluster)-1], 'R_analysis/PaperOutput/conditional_expropriation_polconv_table_cluster.tex')


############################################################################
#######################Henisz panel multinomial#################################



#no controls
nc_polconv_df<-multinom_function(ex_full_panel[c('exprop_numeric', 'exprop_numeric_b1', 'polconv', 'country_num')], 'exprop_numeric', 'exprop_numeric_b1', iterations)
ggsave('R_analysis/PaperOutput/multinom_nocontrols_polconv_plot.pdf', plot=multinom_plot(nc_polconv_df), height=5, width=5.25)


#full controls
fc_polconv_df<-multinom_function(ex_full_panel[c('exprop_numeric', 'exprop_numeric_b1','polconv', 'democracy_p', 'year_bin',
                                                   'll_gdp_pc', 'll_gdp_pc2', 'history', 'region', 'country_num')], 'exprop_numeric', 'exprop_numeric_b1', iterations)
ggsave('R_analysis/PaperOutput/multinom_fullcontrols_polconv_plot.pdf', plot=multinom_plot(fc_polconv_df), height=5, width=5.25)



############################################################################
#######################Henisz panel OLS#################################
m1_panel_polcon_all_p<-lm(num_exprop~polconv+democracy_p+log(lag_gdp_pc)+I(log(lag_gdp_pc)^2)+history+region+year_bin, data=ex_full_panel)
m1_panel_polcon_all_se_p<-sqrt(diag(vcovCluster(m1_panel_polcon_all_p, ex_full_panel$country[is.na(ex_full_panel$democracy_p)==FALSE&is.na(ex_full_panel$polconv)==FALSE&is.na(ex_full_panel$num_exprop)==FALSE])))

m1_panel_polcon_strong_p<-lm(num_strong_exprop~polconv+democracy_p+log(lag_gdp_pc)+I(log(lag_gdp_pc)^2)+history+region+year_bin, data=ex_full_panel)
m1_panel_polcon_strong_se_p<-sqrt(diag(vcovCluster(m1_panel_polcon_strong_p, ex_full_panel$country[is.na(ex_full_panel$democracy_p)==FALSE&is.na(ex_full_panel$polconv)==FALSE&is.na(ex_full_panel$num_strong_exprop)==FALSE])))

m1_panel_polcon_weak_p<-lm(num_weak_exprop~polconv+democracy_p+log(lag_gdp_pc)+I(log(lag_gdp_pc)^2)+history+region+year_bin, data=ex_full_panel)
m1_panel_polcon_weak_se_p<-sqrt(diag(vcovCluster(m1_panel_polcon_weak_p, ex_full_panel$country[is.na(ex_full_panel$democracy_p)==FALSE&is.na(ex_full_panel$polconv)==FALSE&is.na(ex_full_panel$num_weak_exprop)==FALSE])))

ols_panel_polcon<-stargazer(m1_panel_polcon_all_p, m1_panel_polcon_strong_p, m1_panel_polcon_weak_p, 
                            se=list(m1_panel_polcon_all_se_p, m1_panel_polcon_strong_se_p, m1_panel_polcon_weak_se_p),
                            align=TRUE, omit=c('year_bin', 'region','Constant'), header=FALSE, label="table:ols_polcon",
                            covariate.labels=c("Political Constraints", "Democracy", "GDP per capita", "GDP per capita squared", "Expropriation History",
                                               "Constant"), title="Henisz political constraints and expropriation type, panel using OLS", font.size="footnotesize", column.sep.width="15pt",
                            add.lines=list(c("Region/Decade FE", "Y", "Y", "Y")),
                            omit.stat=c("f", "ser"),dep.var.caption  = "DV: Number of expropriations in given year",
                            dep.var.labels=c("Any expropriation","Overt expropriation","Covert expropriation"), no.space=TRUE,
                            notes = "Robust standard errors clustered at the country level")

write(ols_panel_polcon, 'R_analysis/PaperOutput/ols_panel_polcon.tex')





######################################################
############Controlling for Interregnum###############
######################################################

##Conditional LC##
m1_lc_interregnum<-glm(strong_exprop~leg_constraints+interregnum, data=exprop_dem_gdp, family='binomial')
cov.m1_lc_interregnum_cluster <- vcovCL(m1_lc_interregnum, ~country)
robust.se.m1_lc_interregnum_cluster <- sqrt(diag(cov.m1_lc_interregnum_cluster))

m2_lc_interregnum<-glm(strong_exprop~leg_constraints+democracy_p+ll_gdp_pc+ll_gdp_pc2+factor(sector2)+interregnum, data=exprop_dem_gdp, family='binomial')
cov.m2_lc_interregnum_cluster <- vcovCL(m2_lc_interregnum, ~country)
robust.se.m2_lc_interregnum_cluster <- sqrt(diag(cov.m2_lc_interregnum_cluster))

m3_lc_interregnum<-glm(strong_exprop~leg_constraints+ll_gdp_pc+ll_gdp_pc2+factor(sector2)+region+factor(year_bin)+interregnum, data=exprop_dem_gdp, family='binomial')
cov.m3_lc_interregnum_cluster <- vcovCL(m3_lc_interregnum, ~country)
robust.se.m3_lc_interregnum_cluster <- sqrt(diag(cov.m3_lc_interregnum_cluster))


m4_lc_interregnum<-glm(strong_exprop~leg_constraints+democracy_p+ll_gdp_pc+ll_gdp_pc2+factor(sector2)+region+factor(year_bin)+interregnum, data=exprop_dem_gdp, family='binomial')
cov.m4_lc_interregnum_cluster <- vcovCL(m4_lc_interregnum, ~country)
robust.se.m4_lc_interregnum_cluster <- sqrt(diag(cov.m4_lc_interregnum_cluster))


conditional_expropriation_legconstraints_interregnum_table_cluster<-stargazer(m1_lc_interregnum, m2_lc_interregnum, m3_lc_interregnum, m4_lc_interregnum, se=list(robust.se.m1_lc_interregnum_cluster, robust.se.m2_lc_interregnum_cluster, robust.se.m3_lc_interregnum_cluster, robust.se.m4_lc_interregnum_cluster),
                                                                              align=TRUE, omit=c('year_bin', 'region','Constant'), header=FALSE, label="table:conditional_expropriation_legconstraints_interregnum",
                                                                              covariate.labels=c("Legislative Constraints", "Democracy", "GDP per capita", "GDP per capita squared", "Extractive sector",
                                                                                                 "Financial sector", "Manufacturing sector", "Services sector", "Utilities sector", "Interregnum"
                                                                                                 ), title="Overt expropriation and legislative constraints, controlling for interregnum years", font.size="footnotesize", column.sep.width="0pt",
                                                                              add.lines=list(c("Decade/Region FE", "N", "N", "Y","Y")),
                                                                              dep.var.labels = "Use of overt (1) vs. covert (0) expropriation", no.space=TRUE,
                                                                              notes="Robust standard errors clustered at country level")
write(conditional_expropriation_legconstraints_interregnum_table_cluster, 'R_analysis/PaperOutput/conditional_expropriation_legconstraints_interregnum_table_cluster.tex')


##Conditional Vert Acc###
m1_ac_interregnum<-glm(strong_exprop~v2x_veracc+interregnum, data=exprop_dem_gdp, family='binomial')
cov.m1_ac_interregnum_cluster <- vcovCL(m1_ac_interregnum, ~country)
robust.se.m1_ac_interregnum_cluster <- sqrt(diag(cov.m1_ac_interregnum_cluster))

m2_ac_interregnum<-glm(strong_exprop~v2x_veracc+democracy_p+ll_gdp_pc+ll_gdp_pc2+factor(sector2)+interregnum, data=exprop_dem_gdp, family='binomial')
cov.m2_ac_interregnum_cluster <- vcovCL(m2_ac_interregnum, ~country)
robust.se.m2_ac_interregnum_cluster <- sqrt(diag(cov.m2_ac_interregnum_cluster))

m3_ac_interregnum<-glm(strong_exprop~v2x_veracc+ll_gdp_pc+ll_gdp_pc2+factor(sector2)+region+factor(year_bin)+interregnum, data=exprop_dem_gdp, family='binomial')
cov.m3_ac_interregnum_cluster <- vcovCL(m3_ac_interregnum, ~country)
robust.se.m3_ac_interregnum_cluster <- sqrt(diag(cov.m3_ac_interregnum_cluster))


m4_ac_interregnum<-glm(strong_exprop~v2x_veracc+democracy_p+ll_gdp_pc+ll_gdp_pc2+factor(sector2)+region+factor(year_bin)+interregnum, data=exprop_dem_gdp, family='binomial')
cov.m4_ac_interregnum_cluster <- vcovCL(m4_ac_interregnum, ~country)
robust.se.m4_ac_interregnum_cluster <- sqrt(diag(cov.m4_ac_interregnum_cluster))


conditional_expropriation_vertacc_interregnum_table_cluster<-stargazer(m1_ac_interregnum, m2_ac_interregnum, m3_ac_interregnum, m4_ac_interregnum, se=list(robust.se.m1_ac_interregnum_cluster, robust.se.m2_ac_interregnum_cluster, robust.se.m3_ac_interregnum_cluster, robust.se.m4_ac_interregnum_cluster),
                                                                              align=TRUE, omit=c('year', 'region'), header=FALSE, label="table:conditional_expropriation_vertacc_interregnum",
                                                                              covariate.labels=c("Vertical Accountability", "Democracy", "GDP per capita", "GDP per capita squared", "Extractive sector",
                                                                                                 "Financial sector", "Manufacturing sector", "Services sector", "Utilities sector", "Interregnum"
                                                                                                 ), title="Overt expropriation and vertical accountability, controlling for interregnum years", font.size="footnotesize", column.sep.width="0pt",
                                                                              add.lines=list(c("Decade/Region FE", "N", "N", "Y","Y")),
                                                                       dep.var.labels = "Use of overt (1) vs. covert (0) expropriation", no.space=TRUE,
                                                                              notes="Robust standard errors clustered at country level")
write(conditional_expropriation_vertacc_interregnum_table_cluster, 'R_analysis/PaperOutput/conditional_expropriation_vertacc_interregnum_table_cluster.tex')

##Panel Legislative Constraints OLS##

m1_interregnum_lc_panel_all_interregnum<-lm(num_exprop~ leg_constraints+democracy_p +interregnum +log(lag_gdp_pc)+I(log(lag_gdp_pc)^2)+history+region+year_bin, data=ex_full_panel)
m1_interregnum_lc_panel_all_se_interregnum<-sqrt(diag(vcovCluster(m1_interregnum_lc_panel_all_interregnum, ex_full_panel$country[is.na(ex_full_panel$democracy_p)==FALSE&is.na(ex_full_panel$leg_constraints)==FALSE&is.na(ex_full_panel$num_exprop)==FALSE])))

m1_interregnum_lc_panel_strong_interregnum<-lm(num_strong_exprop~ leg_constraints+democracy_p +interregnum +log(lag_gdp_pc)+I(log(lag_gdp_pc)^2)+history+region+year_bin, data=ex_full_panel)
m1_interregnum_lc_panel_strong_se_interregnum<-sqrt(diag(vcovCluster(m1_interregnum_lc_panel_strong_interregnum, ex_full_panel$country[is.na(ex_full_panel$leg_constraints)==FALSE&is.na(ex_full_panel$interregnum)==FALSE&is.na(ex_full_panel$democracy_p)==FALSE&is.na(ex_full_panel$num_strong_exprop)==FALSE])))

m1_interregnum_lc_panel_weak_interregnum<-lm(num_weak_exprop~ leg_constraints+democracy_p + interregnum +log(lag_gdp_pc)+I(log(lag_gdp_pc)^2)+history+region+year_bin, data=ex_full_panel)
m1_interregnum_lc_panel_weak_se_interregnum<-sqrt(diag(vcovCluster(m1_interregnum_lc_panel_weak_interregnum, ex_full_panel$country[is.na(ex_full_panel$leg_constraints)==FALSE&is.na(ex_full_panel$interregnum)==FALSE&is.na(ex_full_panel$democracy_p)==FALSE&is.na(ex_full_panel$num_weak_exprop)==FALSE])))

ols_interregnum_lc_panel<-stargazer(m1_interregnum_lc_panel_all_interregnum, m1_interregnum_lc_panel_strong_interregnum, m1_interregnum_lc_panel_weak_interregnum, 
                                    se=list(m1_interregnum_lc_panel_all_se_interregnum, m1_interregnum_lc_panel_strong_se_interregnum, m1_interregnum_lc_panel_weak_se_interregnum),
                                    align=TRUE, omit=c('year_bin', 'region','Constant'), header=FALSE, label="table:ols_interregnum_lc_panel",
                                    covariate.labels=c('Legislative Constraints', "Democracy", 'Interregnum', "GDP per capita", "GDP per capita squared", "Expropriation History"
                                                       ), title="Legislative constraints and expropriation type, panel using OLS, controlling for interregnum years", font.size="footnotesize", column.sep.width="15pt",
                                    add.lines=list(c("Region/Decade FE", "Y", "Y", "Y")),
                                    omit.stat=c("f", "ser"),dep.var.caption  = "DV: Number of expropriations in given year",
                                    dep.var.labels=c("Any expropriation","Overt expropriation","Covert expropriation"), no.space=TRUE,
                                    notes = "Robust standard errors clustered at the country level")

write(ols_interregnum_lc_panel, 'R_analysis/PaperOutput/ols_interregnum_lc_panel.tex')


##Panel Vertical Accountability OLS##
m1_interregnum_ac_panel_all_interregnum<-lm(num_exprop~ v2x_veracc+democracy_p +interregnum +log(lag_gdp_pc)+I(log(lag_gdp_pc)^2)+history+region+year_bin, data=ex_full_panel)
m1_interregnum_ac_panel_all_se_interregnum<-sqrt(diag(vcovCluster(m1_interregnum_ac_panel_all_interregnum, ex_full_panel$country[is.na(ex_full_panel$democracy_p)==FALSE&is.na(ex_full_panel$v2x_veracc)==FALSE&is.na(ex_full_panel$num_exprop)==FALSE])))

m1_interregnum_ac_panel_strong_interregnum<-lm(num_strong_exprop~ v2x_veracc+democracy_p +interregnum +log(lag_gdp_pc)+I(log(lag_gdp_pc)^2)+history+region+year_bin, data=ex_full_panel)
m1_interregnum_ac_panel_strong_se_interregnum<-sqrt(diag(vcovCluster(m1_interregnum_ac_panel_strong_interregnum, ex_full_panel$country[is.na(ex_full_panel$v2x_veracc)==FALSE&is.na(ex_full_panel$interregnum)==FALSE&is.na(ex_full_panel$democracy_p)==FALSE&is.na(ex_full_panel$num_strong_exprop)==FALSE])))

m1_interregnum_ac_panel_weak_interregnum<-lm(num_weak_exprop~ v2x_veracc+democracy_p + interregnum +log(lag_gdp_pc)+I(log(lag_gdp_pc)^2)+history+region+year_bin, data=ex_full_panel)
m1_interregnum_ac_panel_weak_se_interregnum<-sqrt(diag(vcovCluster(m1_interregnum_ac_panel_weak_interregnum, ex_full_panel$country[is.na(ex_full_panel$v2x_veracc)==FALSE&is.na(ex_full_panel$interregnum)==FALSE&is.na(ex_full_panel$democracy_p)==FALSE&is.na(ex_full_panel$num_weak_exprop)==FALSE])))

ols_interregnum_ac_panel<-stargazer(m1_interregnum_ac_panel_all_interregnum, m1_interregnum_ac_panel_strong_interregnum, m1_interregnum_ac_panel_weak_interregnum, 
                                    se=list(m1_interregnum_ac_panel_all_se_interregnum, m1_interregnum_ac_panel_strong_se_interregnum, m1_interregnum_ac_panel_weak_se_interregnum),
                                    align=TRUE, omit=c('year_bin', 'region','Constant'), header=FALSE, label="table:ols_interregnum_lc_panel",
                                    covariate.labels=c('Vertical Accountability', "Democracy", 'Interregnum', "GDP per capita", "GDP per capita squared", "Expropriation History"
                                                       ), title="Vertical Accountability and expropriation type, panel using OLS, controlling for interregnum years", font.size="footnotesize", column.sep.width="15pt",
                                    add.lines=list(c("Region/Decade FE", "Y", "Y", "Y")),
                                    omit.stat=c("f", "ser"),dep.var.caption  = "DV: Number of expropriations in given year",
                                    dep.var.labels=c("Any expropriation","Overt expropriation","Covert expropriation"), no.space=TRUE,
                                    notes = "Robust standard errors clustered at the country level")

write(ols_interregnum_ac_panel, 'R_analysis/PaperOutput/ols_interregnum_ac_panel.tex')


###Leg constraints multinomial logit##
multinom_fullcontrols_lc_interregnum<-multinom_function(ex_full_panel[c('exprop_numeric', 'exprop_numeric_b1', 'leg_constraints','year_bin', 'democracy_p', 'interregnum',
                                                                          'll_gdp_pc', 'll_gdp_pc2', 'history', 'region', 'country_num')], 'exprop_numeric', 'exprop_numeric_b1', iterations)

ggsave('R_analysis/PaperOutput/multinom_fullcontrols_lc_interregnum_plot.pdf', plot=multinom_plot(multinom_fullcontrols_lc_interregnum), height=5, width=5.25)

###Vert accountability multinomial logit##
multinom_fullcontrols_ac_interregnum<-multinom_function(ex_full_panel[c('exprop_numeric', 'exprop_numeric_b1', 'v2x_veracc','year_bin', 'democracy_p', 'interregnum',
                                                                        'll_gdp_pc', 'll_gdp_pc2', 'history', 'region', 'country_num')], 'exprop_numeric', 'exprop_numeric_b1', iterations)

ggsave('R_analysis/PaperOutput/multinom_fullcontrols_ac_interregnum_plot.pdf', plot=multinom_plot(multinom_fullcontrols_ac_interregnum), height=5, width=5.25)



######################################################
############Controlling for Coups###############
######################################################


##Legislative constraints, conditional###

m1_lc_coup<-glm(strong_exprop~leg_constraints+coup, data=exprop_dem_gdp, family='binomial')
cov.m1_lc_coup_cluster <- vcovCL(m1_lc_coup, ~country)
robust.se.m1_lc_coup_cluster <- sqrt(diag(cov.m1_lc_coup_cluster))

m2_lc_coup<-glm(strong_exprop~leg_constraints+democracy_p+ll_gdp_pc+ll_gdp_pc2+factor(sector2)+coup, data=exprop_dem_gdp, family='binomial')
cov.m2_lc_coup_cluster <- vcovCL(m2_lc_coup, ~country)
robust.se.m2_lc_coup_cluster <- sqrt(diag(cov.m2_lc_coup_cluster))

m3_lc_coup<-glm(strong_exprop~leg_constraints+ll_gdp_pc+ll_gdp_pc2+factor(sector2)+region+factor(year_bin)+coup, data=exprop_dem_gdp, family='binomial')
cov.m3_lc_coup_cluster <- vcovCL(m3_lc_coup, ~country)
robust.se.m3_lc_coup_cluster <- sqrt(diag(cov.m3_lc_coup_cluster))

m4_lc_coup<-glm(strong_exprop~leg_constraints+democracy_p+ll_gdp_pc+ll_gdp_pc2+factor(sector2)+region+factor(year_bin)+coup, data=exprop_dem_gdp, family='binomial')
cov.m4_lc_coup_cluster <- vcovCL(m4_lc_coup, ~country)
robust.se.m4_lc_coup_cluster <- sqrt(diag(cov.m4_lc_coup_cluster))

conditional_expropriation_legconstraints_coup_table_cluster<-stargazer(m1_lc_coup, m2_lc_coup, m3_lc_coup, m4_lc_coup, se=list(robust.se.m1_lc_coup_cluster, robust.se.m2_lc_coup_cluster, robust.se.m3_lc_coup_cluster, robust.se.m4_lc_coup_cluster),
                                                                       align=TRUE, omit=c('year', 'region'), header=FALSE, label="table:conditional_expropriation_legconstraints_coup",
                                                                       covariate.labels=c("Legislative Constraints", "Democracy", "GDP per capita", "GDP per capita squared", "Extractive sector",
                                                                                          "Financial sector", "Manufacturing sector", "Services sector", "Utilities sector", "Coup",
                                                                                          "Constant"), title="Overt expropriation and legislative constraints, controlling for coups", font.size="footnotesize", column.sep.width="0pt",
                                                                       add.lines=list(c("Decade/Region FE", "N", "N", "Y","Y")),
                                                                       dep.var.labels = "Use of overt (1) vs. covert (0) expropriation", no.space=TRUE,
                                                                       notes="Robust standard errors clustered at country level")
write(conditional_expropriation_legconstraints_coup_table_cluster, 'R_analysis/PaperOutput/conditional_expropriation_legconstraints_coup_table_cluster.tex')

###Vertical accountability, conditional###


m1_ac_coup<-glm(strong_exprop~v2x_veracc+coup, data=exprop_dem_gdp, family='binomial')
cov.m1_ac_coup_cluster <- vcovCL(m1_ac_coup, ~country)
robust.se.m1_ac_coup_cluster <- sqrt(diag(cov.m1_ac_coup_cluster))

m2_ac_coup<-glm(strong_exprop~v2x_veracc+democracy_p+ll_gdp_pc+ll_gdp_pc2+factor(sector2)+coup, data=exprop_dem_gdp, family='binomial')
cov.m2_ac_coup_cluster <- vcovCL(m2_ac_coup, ~country)
robust.se.m2_ac_coup_cluster <- sqrt(diag(cov.m2_ac_coup_cluster))

m3_ac_coup<-glm(strong_exprop~v2x_veracc+ll_gdp_pc+ll_gdp_pc2+factor(sector2)+region+factor(year_bin)+coup, data=exprop_dem_gdp, family='binomial')
cov.m3_ac_coup_cluster <- vcovCL(m3_ac_coup, ~country)
robust.se.m3_ac_coup_cluster <- sqrt(diag(cov.m3_ac_coup_cluster))

m4_ac_coup<-glm(strong_exprop~v2x_veracc+democracy_p+ll_gdp_pc+ll_gdp_pc2+factor(sector2)+region+factor(year_bin)+coup, data=exprop_dem_gdp, family='binomial')
cov.m4_ac_coup_cluster <- vcovCL(m4_ac_coup, ~country)
robust.se.m4_ac_coup_cluster <- sqrt(diag(cov.m4_ac_coup_cluster))

conditional_expropriation_vert_acc_coup_table_cluster<-stargazer(m1_ac_coup, m2_ac_coup, m3_ac_coup, m4_ac_coup, se=list(robust.se.m1_ac_coup_cluster, robust.se.m2_ac_coup_cluster, robust.se.m3_ac_coup_cluster, robust.se.m4_ac_coup_cluster),
                                                                 align=TRUE, omit=c('year_bin', 'region','Constant'), header=FALSE, label="table:conditional_expropriation_vertacc_coup",
                                                                 covariate.labels=c("Vertical Accountability", "Democracy", "GDP per capita", "GDP per capita squared", "Extractive sector",
                                                                                    "Financial sector", "Manufacturing sector", "Services sector", "Utilities sector", "Coup"
                                                                                    ), title="Overt expropriation and vertical accountability, controlling for coups", font.size="footnotesize", column.sep.width="0pt",
                                                                 add.lines=list(c("Decade/Region FE", "N", "N", "Y","Y")),
                                                                 dep.var.labels = "Use of overt (1) vs. covert (0) expropriation", no.space=TRUE,
                                                                 notes="Robust standard errors clustered at country level")
write(conditional_expropriation_vert_acc_coup_table_cluster, 'R_analysis/PaperOutput/conditional_expropriation_vert_acc_coup_table_cluster.tex')



##Panel Legislative Constraints OLS##

m1_coup_lc_panel_all<-lm(num_exprop~ leg_constraints+democracy_p +coup +log(lag_gdp_pc)+I(log(lag_gdp_pc)^2)+history+region+year_bin, data=ex_full_panel)
m1_coup_lc_panel_all_se<-sqrt(diag(vcovCluster(m1_coup_lc_panel_all, ex_full_panel$country[is.na(ex_full_panel$democracy_p)==FALSE&is.na(ex_full_panel$leg_constraints)==FALSE&is.na(ex_full_panel$num_exprop)==FALSE&is.na(ex_full_panel$coup)==FALSE])))

m1_coup_lc_panel_strong<-lm(num_strong_exprop~ leg_constraints+democracy_p +coup +log(lag_gdp_pc)+I(log(lag_gdp_pc)^2)+history+region+year_bin, data=ex_full_panel)
m1_coup_lc_panel_strong_se<-sqrt(diag(vcovCluster(m1_coup_lc_panel_strong, ex_full_panel$country[is.na(ex_full_panel$leg_constraints)==FALSE&is.na(ex_full_panel$coup)==FALSE&is.na(ex_full_panel$democracy_p)==FALSE&is.na(ex_full_panel$num_strong_exprop)==FALSE])))

m1_coup_lc_panel_weak<-lm(num_weak_exprop~ leg_constraints+democracy_p + coup +log(lag_gdp_pc)+I(log(lag_gdp_pc)^2)+history+region+year_bin, data=ex_full_panel)
m1_coup_lc_panel_weak_se<-sqrt(diag(vcovCluster(m1_coup_lc_panel_weak, ex_full_panel$country[is.na(ex_full_panel$leg_constraints)==FALSE&is.na(ex_full_panel$coup)==FALSE&is.na(ex_full_panel$democracy_p)==FALSE&is.na(ex_full_panel$num_weak_exprop)==FALSE])))

ols_coup_lc_panel<-stargazer(m1_coup_lc_panel_all, m1_coup_lc_panel_strong, m1_coup_lc_panel_weak, 
                                    se=list(m1_coup_lc_panel_all_se, m1_coup_lc_panel_strong_se, m1_coup_lc_panel_weak_se),
                                    align=TRUE, omit=c('year_bin', 'region','Constant'), header=FALSE, label="table:ols_coup_lc_panel",
                                    covariate.labels=c('Legislative Constraints', "Democracy", 'Coup', "GDP per capita", "GDP per capita squared", "Expropriation History"
                                                       ), title="Legislative constraints and expropriation type, panel using OLS, controlling for coup years", font.size="footnotesize", column.sep.width="15pt",
                                    add.lines=list(c("Region/Decade FE", "Y", "Y", "Y")),
                                    omit.stat=c("f", "ser"),dep.var.caption  = "DV: Number of expropriations in given year",
                                    dep.var.labels=c("Any expropriation","Overt expropriation","Covert expropriation"), no.space=TRUE,
                                    notes = "Robust standard errors clustered at the country level")

write(ols_coup_lc_panel, 'R_analysis/PaperOutput/ols_coup_lc_panel.tex')


##Panel Vertical Accountability OLS##
m1_coup_ac_panel_all<-lm(num_exprop~ v2x_veracc+democracy_p +coup +log(lag_gdp_pc)+I(log(lag_gdp_pc)^2)+history+region+year_bin, data=ex_full_panel)
m1_coup_ac_panel_all_se<-sqrt(diag(vcovCluster(m1_coup_ac_panel_all, ex_full_panel$country[is.na(ex_full_panel$democracy_p)==FALSE&is.na(ex_full_panel$v2x_veracc)==FALSE&is.na(ex_full_panel$num_exprop)==FALSE&is.na(ex_full_panel$coup)==FALSE])))

m1_coup_ac_panel_strong<-lm(num_strong_exprop~ v2x_veracc+democracy_p +coup +log(lag_gdp_pc)+I(log(lag_gdp_pc)^2)+history+region+year_bin, data=ex_full_panel)
m1_coup_ac_panel_strong_se<-sqrt(diag(vcovCluster(m1_coup_ac_panel_strong, ex_full_panel$country[is.na(ex_full_panel$v2x_veracc)==FALSE&is.na(ex_full_panel$coup)==FALSE&is.na(ex_full_panel$democracy_p)==FALSE&is.na(ex_full_panel$num_strong_exprop)==FALSE])))

m1_coup_ac_panel_weak<-lm(num_weak_exprop~ v2x_veracc+democracy_p + coup +log(lag_gdp_pc)+I(log(lag_gdp_pc)^2)+history+region+year_bin, data=ex_full_panel)
m1_coup_ac_panel_weak_se<-sqrt(diag(vcovCluster(m1_coup_ac_panel_weak, ex_full_panel$country[is.na(ex_full_panel$v2x_veracc)==FALSE&is.na(ex_full_panel$coup)==FALSE&is.na(ex_full_panel$democracy_p)==FALSE&is.na(ex_full_panel$num_weak_exprop)==FALSE])))

ols_coup_ac_panel<-stargazer(m1_coup_ac_panel_all, m1_coup_ac_panel_strong, m1_coup_ac_panel_weak, 
                             se=list(m1_coup_ac_panel_all_se, m1_coup_ac_panel_strong_se, m1_coup_ac_panel_weak_se),
                             align=TRUE, omit=c('year_bin', 'region','Constant'), header=FALSE, label="table:ols_coup_ac_panel",
                             covariate.labels=c('Vertical Accountability', "Democracy", 'Coup', "GDP per capita", "GDP per capita squared", "Expropriation History"
                             ), title="Vertical accountability and expropriation type, panel using OLS, controlling for coup years", font.size="footnotesize", column.sep.width="15pt",
                             add.lines=list(c("Region/Decade FE", "Y", "Y", "Y")),
                             omit.stat=c("f", "ser"),dep.var.caption  = "DV: Number of expropriations in given year",
                             dep.var.labels=c("Any expropriation","Overt expropriation","Covert expropriation"), no.space=TRUE,
                             notes = "Robust standard errors clustered at the country level")

write(ols_coup_ac_panel, 'R_analysis/PaperOutput/ols_coup_ac_panel.tex')


###Leg constraints multinomial logit##
multinom_fullcontrols_lc_coup<-multinom_function(ex_full_panel[c('exprop_numeric', 'exprop_numeric_b1', 'leg_constraints','year_bin', 'democracy_p', 'coup',
                                                                        'll_gdp_pc', 'll_gdp_pc2', 'history', 'region', 'country_num')], 'exprop_numeric', 'exprop_numeric_b1', iterations)

ggsave('R_analysis/PaperOutput/multinom_fullcontrols_lc_coup_plot.pdf', plot=multinom_plot(multinom_fullcontrols_lc_coup), height=5, width=5.25)

###Vert accountability multinomial logit##
multinom_fullcontrols_ac_coup<-multinom_function(ex_full_panel[c('exprop_numeric', 'exprop_numeric_b1', 'v2x_veracc','year_bin', 'democracy_p', 'coup',
                                                                        'll_gdp_pc', 'll_gdp_pc2', 'history', 'region', 'country_num')], 'exprop_numeric', 'exprop_numeric_b1', iterations)

ggsave('R_analysis/PaperOutput/multinom_fullcontrols_ac_coup_plot.pdf', plot=multinom_plot(multinom_fullcontrols_ac_coup), height=5, width=5.25)

#####################################################
#######Controlling for socialism#####################
###############################################################

m1_lc_socialism<-glm(strong_exprop~leg_constraints+v2csanmvch_6, data=exprop_dem_gdp, family='binomial')
cov.m1_lc_socialism_cluster <- vcovCL(m1_lc_socialism, ~country)
robust.se.m1_lc_socialism_cluster <- sqrt(diag(cov.m1_lc_socialism_cluster))

m2_lc_socialism<-glm(strong_exprop~leg_constraints+democracy_p+ll_gdp_pc+ll_gdp_pc2+factor(sector2)+v2csanmvch_6, data=exprop_dem_gdp, family='binomial')
cov.m2_lc_socialism_cluster <- vcovCL(m2_lc_socialism, ~country)
robust.se.m2_lc_socialism_cluster <- sqrt(diag(cov.m2_lc_socialism_cluster))

m3_lc_socialism<-glm(strong_exprop~leg_constraints+ll_gdp_pc+ll_gdp_pc2+factor(sector2)+region+factor(year_bin)+v2csanmvch_6, data=exprop_dem_gdp, family='binomial')
cov.m3_lc_socialism_cluster <- vcovCL(m3_lc_socialism, ~country)
robust.se.m3_lc_socialism_cluster <- sqrt(diag(cov.m3_lc_socialism_cluster))

m4_lc_socialism<-glm(strong_exprop~leg_constraints+democracy_p+ll_gdp_pc+ll_gdp_pc2+factor(sector2)+region+factor(year_bin)+v2csanmvch_6, data=exprop_dem_gdp, family='binomial')
cov.m4_lc_socialism_cluster <- vcovCL(m4_lc_socialism, ~country)
robust.se.m4_lc_socialism_cluster <- sqrt(diag(cov.m4_lc_socialism_cluster))

conditional_expropriation_legconstraints_socialism_table_cluster<-stargazer(m1_lc_socialism, m2_lc_socialism, m3_lc_socialism, m4_lc_socialism, se=list(robust.se.m1_lc_socialism_cluster, robust.se.m2_lc_socialism_cluster, robust.se.m3_lc_socialism_cluster, robust.se.m4_lc_socialism_cluster),
                                                                            align=TRUE, omit=c('year_bin', 'region','Constant'), header=FALSE, label="table:conditional_expropriation_legconstraints_socialism",
                                                                            covariate.labels=c("Legislative Constraints", "Democracy", "GDP per capita", "GDP per capita squared", "Extractive sector",
                                                                                               "Financial sector", "Manufacturing sector", "Services sector", "Utilities sector", "Socialism"
                                                                            ), title="Legislative Constraints and Propensity to Use Overt Expropriation, controlling for socialism", font.size="footnotesize", column.sep.width="0pt",
                                                                            add.lines=list(c("Decade/Region FE", "N", "N", "Y","Y")),
                                                                            dep.var.labels="Use of overt (1) vs. covert (0) expropriation", no.space=TRUE,
                                                                            notes="Robust standard errors clustered at country level")
write(conditional_expropriation_legconstraints_socialism_table_cluster, 'R_analysis/PaperOutput/conditional_expropriation_legconstraints_socialism_table_cluster.tex')

####Panel Analysis, OLS Leg const, controlling for socialism####

m1_socialism_panel_all_socialism<-lm(num_exprop~ leg_constraints+democracy_p +v2csanmvch_6 +log(lag_gdp_pc)+I(log(lag_gdp_pc)^2)+history+region+year_bin, data=ex_full_panel)
m1_socialism_panel_all_se_socialism<-sqrt(diag(vcovCluster(m1_socialism_panel_all_socialism, ex_full_panel$country[is.na(ex_full_panel$leg_constraints)==FALSE&is.na(ex_full_panel$v2csanmvch_6)==F&is.na(ex_full_panel$num_exprop)==FALSE&is.na(ex_full_panel$democracy_p)==FALSE])))

m1_socialism_panel_strong_socialism<-lm(num_strong_exprop~ leg_constraints+democracy_p +v2csanmvch_6 +log(lag_gdp_pc)+I(log(lag_gdp_pc)^2)+history+region+year_bin, data=ex_full_panel)
m1_socialism_panel_strong_se_socialism<-sqrt(diag(vcovCluster(m1_socialism_panel_strong_socialism, ex_full_panel$country[is.na(ex_full_panel$leg_constraints)==FALSE&is.na(ex_full_panel$v2csanmvch_6)==F&is.na(ex_full_panel$num_strong_exprop)==FALSE&is.na(ex_full_panel$democracy_p)==FALSE])))

m1_socialism_panel_weak_socialism<-lm(num_weak_exprop~ leg_constraints+democracy_p + v2csanmvch_6 +log(lag_gdp_pc)+I(log(lag_gdp_pc)^2)+history+region+year_bin, data=ex_full_panel)
m1_socialism_panel_weak_se_socialism<-sqrt(diag(vcovCluster(m1_socialism_panel_weak_socialism, ex_full_panel$country[is.na(ex_full_panel$leg_constraints)==FALSE&is.na(ex_full_panel$v2csanmvch_6)==F&is.na(ex_full_panel$num_weak_exprop)==FALSE&is.na(ex_full_panel$democracy_p)==FALSE])))

ols_socialism_panel_lc<-stargazer(m1_socialism_panel_all_socialism, m1_socialism_panel_strong_socialism, m1_socialism_panel_weak_socialism, 
                                  se=list(m1_socialism_panel_all_se_socialism, m1_socialism_panel_strong_se_socialism, m1_socialism_panel_weak_se_socialism),
                                  align=TRUE, omit=c('year_bin', 'region','Constant'), header=FALSE, label="table:ols_socialism_panel",
                                  covariate.labels=c("Legislative Constraints", 'Democracy', 'Socialism', "GDP per capita", "GDP per capita squared", "Expropriation History" 
                                  ), title="Legislative constraints and expropriation type, panel using OLS, controlling for socialism", font.size="footnotesize", column.sep.width="15pt",
                                  add.lines=list(c("Region/Decade FE", "Y", "Y", "Y")),
                                  omit.stat=c("f", "ser"),dep.var.caption  = "DV: Number of expropriations in given year",
                                  dep.var.labels=c("Any expropriation","Overt expropriation","Covert expropriation"), no.space=TRUE,
                                  notes = "Robust standard errors clustered at the country level")

write(ols_socialism_panel_lc, 'R_analysis/PaperOutput/ols_socialism_panel_lc.tex')

#####multinomial logit, controlling for socialism

multinom_fullcontrols_lc_socialism<-multinom_function(ex_full_panel[c('exprop_numeric', 'exprop_numeric_b1', 'leg_constraints','year_bin','region', 'democracy_p', 'v2csanmvch_6',
                                                                      'll_gdp_pc', 'll_gdp_pc2', 'history', 'country_num')], 'exprop_numeric', 'exprop_numeric_b1', iterations)
ggsave('R_analysis/PaperOutput/multinom_fullcontrols_lc_socialism_plot.pdf', plot=multinom_plot(multinom_fullcontrols_lc_socialism), height=5, width=5.25)


#################################################
###############Year Fixed effects###############
#################################################

##Conditional LC

m1_lc_year<-glm(strong_exprop~leg_constraints, data=exprop_dem_gdp, family='binomial')
cov.m1_lc_cluster_year <- vcovCL(m1_lc_year, ~country)
robust.se.m1_lc_cluster_year <- sqrt(diag(cov.m1_lc_cluster_year))

m2_lc_year<-glm(strong_exprop~leg_constraints+democracy_p+ll_gdp_pc+ll_gdp_pc2+factor(sector2), data=exprop_dem_gdp, family='binomial')
cov.m2_lc_cluster_year <- vcovCL(m2_lc_year, ~country)
robust.se.m2_lc_cluster_year <- sqrt(diag(cov.m2_lc_cluster_year))

m3_lc_year<-glm(strong_exprop~leg_constraints+ll_gdp_pc+ll_gdp_pc2+factor(sector2)+region+factor(year), data=exprop_dem_gdp, family='binomial')
cov.m3_lc_cluster_year <- vcovCL(m3_lc_year, ~country)
robust.se.m3_lc_cluster_year <- sqrt(diag(cov.m3_lc_cluster_year))

m4_lc_year<-glm(strong_exprop~leg_constraints+democracy_p+ll_gdp_pc+ll_gdp_pc2+factor(sector2)+region+factor(year), data=exprop_dem_gdp, family='binomial')
cov.m4_lc_cluster_year <- vcovCL(m4_lc_year, ~country)
robust.se.m4_lc_cluster_year <- sqrt(diag(cov.m4_lc_cluster_year))


clustered_conditional_expropriation_legconstraints_table_year<-stargazer(m1_lc_year, m2_lc_year, m3_lc_year, m4_lc_year, se=list(robust.se.m1_lc_cluster_year, robust.se.m2_lc_cluster_year, robust.se.m3_lc_cluster_year, robust.se.m4_lc_cluster_year),
                                                                    align=TRUE, omit=c('region','year','Constant'), header=FALSE, label="table:conditional_expropriation_legconstraints_year_fes",
                                                                    covariate.labels=c("Legislative Constraints", "Democracy", "GDP per capita", "GDP per capita squared", "Extractive sector",
                                                                                       "Financial sector", "Manufacturing sector", "Services sector", "Utilities sector"), title="Legislative Constraints and Propensity to Use Overt Expropriation (Year FEs)", font.size="footnotesize", column.sep.width="0pt",
                                                                    add.lines=list(c("Year/Region FE", "N", "N", "Y","Y")),
                                                                    dep.var.labels="Use of overt (1) vs. covert (0) expropriation", no.space=TRUE,
                                                                    notes="Robust standard errors clustered at country level")
write(clustered_conditional_expropriation_legconstraints_table_year[4:length(clustered_conditional_expropriation_legconstraints_table_year)-1], 'R_analysis/PaperOutput/conditional_expropriation_legconstraints_table_year.tex')


##Conditional AC

m1_ac_year<-glm(strong_exprop~v2x_veracc, data=exprop_dem_gdp, family='binomial')
cov.m1_ac_cluster_year <- vcovCL(m1_ac_year, ~country)
robust.se.m1_ac_cluster_year <- sqrt(diag(cov.m1_ac_cluster_year))

m2_ac_year<-glm(strong_exprop~v2x_veracc+democracy_p+ll_gdp_pc+ll_gdp_pc2+factor(sector2), data=exprop_dem_gdp, family='binomial')
cov.m2_ac_cluster_year <- vcovCL(m2_ac_year, ~country)
robust.se.m2_ac_cluster_year <- sqrt(diag(cov.m2_ac_cluster_year))

m3_ac_year<-glm(strong_exprop~v2x_veracc+ll_gdp_pc+ll_gdp_pc2+factor(sector2)+region+factor(year), data=exprop_dem_gdp, family='binomial')
cov.m3_ac_cluster_year <- vcovCL(m3_ac_year, ~country)
robust.se.m3_ac_cluster_year <- sqrt(diag(cov.m3_ac_cluster_year))

m4_ac_year<-glm(strong_exprop~v2x_veracc+democracy_p+ll_gdp_pc+ll_gdp_pc2+factor(sector2)+region+factor(year), data=exprop_dem_gdp, family='binomial')
cov.m4_ac_cluster_year <- vcovCL(m4_ac_year, ~country)
robust.se.m4_ac_cluster_year <- sqrt(diag(cov.m4_ac_cluster_year))


clustered_conditional_expropriation_vertacc_table_year<-stargazer(m1_ac_year, m2_ac_year, m3_ac_year, m4_ac_year, se=list(robust.se.m1_ac_cluster_year, robust.se.m2_ac_cluster_year, robust.se.m3_ac_cluster_year, robust.se.m4_ac_cluster_year),
                                                                         align=TRUE, omit=c('region','year','Constant'), header=FALSE, label="table:conditional_expropriation_vertacc_year_fes",
                                                                         covariate.labels=c("Vertical Accountability", "Democracy", "GDP per capita", "GDP per capita squared", "Extractive sector",
                                                                                            "Financial sector", "Manufacturing sector", "Services sector", "Utilities sector"), title="Vertical Accountability and Propensity to Use Overt Expropriation (Year FEs)", font.size="footnotesize", column.sep.width="0pt",
                                                                         add.lines=list(c("Year/Region FE", "N", "N", "Y","Y")),
                                                                         dep.var.labels="Use of overt (1) vs. covert (0) expropriation", no.space=TRUE,
                                                                         notes="Robust standard errors clustered at country level")
write(clustered_conditional_expropriation_vertacc_table_year[4:length(clustered_conditional_expropriation_vertacc_table_year)-1], 'R_analysis/PaperOutput/conditional_expropriation_vertacc_table_year.tex')


#Panel LC
m1_panel_lc_all_p_year<-lm(num_exprop~leg_constraints+democracy_p+log(lag_gdp_pc)+I(log(lag_gdp_pc)^2)+history+region+factor(year), data=ex_full_panel)
m1_panel_lc_all_se_p_year<-sqrt(diag(vcovCluster(m1_panel_lc_all_p_year, ex_full_panel$country[is.na(ex_full_panel$democracy_p)==FALSE&is.na(ex_full_panel$leg_constraints)==FALSE&is.na(ex_full_panel$num_exprop)==FALSE])))

m1_panel_lc_strong_p_year<-lm(num_strong_exprop~leg_constraints+democracy_p+log(lag_gdp_pc)+I(log(lag_gdp_pc)^2)+history+region+factor(year), data=ex_full_panel)
m1_panel_lc_strong_se_p_year<-sqrt(diag(vcovCluster(m1_panel_lc_strong_p_year, ex_full_panel$country[is.na(ex_full_panel$democracy_p)==FALSE&is.na(ex_full_panel$leg_constraints)==FALSE&is.na(ex_full_panel$num_strong_exprop)==FALSE])))

m1_panel_lc_weak_p_year<-lm(num_weak_exprop~leg_constraints+democracy_p+log(lag_gdp_pc)+I(log(lag_gdp_pc)^2)+history+region+factor(year), data=ex_full_panel)
m1_panel_lc_weak_se_p_year<-sqrt(diag(vcovCluster(m1_panel_lc_weak_p_year, ex_full_panel$country[is.na(ex_full_panel$democracy_p)==FALSE&is.na(ex_full_panel$leg_constraints)==FALSE&is.na(ex_full_panel$num_weak_exprop)==FALSE])))

ols_panel_lc_year<-stargazer(m1_panel_lc_all_p_year, m1_panel_lc_strong_p_year, m1_panel_lc_weak_p_year, 
                        se=list(m1_panel_lc_all_se_p_year, m1_panel_lc_strong_se_p_year, m1_panel_lc_weak_se_p_year),
                        align=TRUE, omit=c('year', 'region','Constant'), header=FALSE, label="table:ols_lc",
                        covariate.labels=c("Legislative Constraints", "Democracy", "GDP per capita", "GDP per capita squared", "Expropriation History"
                        ), title="Legislative constraints and likelihood of using different types of expropriation, OLS panel with year FEs", font.size="footnotesize", column.sep.width="15pt",
                        add.lines=list(c("Region/Year FE", "Y", "Y", "Y")),
                        omit.stat=c("f", "ser"),dep.var.caption  = "DV: Number of expropriations in given year",
                        dep.var.labels=c("Any expropriation","Overt expropriation","Covert expropriation"), no.space=TRUE,
                        notes = "Robust standard errors clustered at the country level")

write(ols_panel_lc_year, 'R_analysis/PaperOutput/ols_panel_lc_year.tex')


#Panel AC
m1_panel_ac_all_p_year<-lm(num_exprop~v2x_veracc+democracy_p+log(lag_gdp_pc)+I(log(lag_gdp_pc)^2)+history+region+factor(year), data=ex_full_panel)
m1_panel_ac_all_se_p_year<-sqrt(diag(vcovCluster(m1_panel_ac_all_p_year, ex_full_panel$country[is.na(ex_full_panel$democracy_p)==FALSE&is.na(ex_full_panel$v2x_veracc)==FALSE&is.na(ex_full_panel$num_exprop)==FALSE])))

m1_panel_ac_strong_p_year<-lm(num_strong_exprop~v2x_veracc+democracy_p+log(lag_gdp_pc)+I(log(lag_gdp_pc)^2)+history+region+factor(year), data=ex_full_panel)
m1_panel_ac_strong_se_p_year<-sqrt(diag(vcovCluster(m1_panel_ac_strong_p_year, ex_full_panel$country[is.na(ex_full_panel$democracy_p)==FALSE&is.na(ex_full_panel$v2x_veracc)==FALSE&is.na(ex_full_panel$num_strong_exprop)==FALSE])))

m1_panel_ac_weak_p_year<-lm(num_weak_exprop~v2x_veracc+democracy_p+log(lag_gdp_pc)+I(log(lag_gdp_pc)^2)+history+region+factor(year), data=ex_full_panel)
m1_panel_ac_weak_se_p_year<-sqrt(diag(vcovCluster(m1_panel_ac_weak_p_year, ex_full_panel$country[is.na(ex_full_panel$democracy_p)==FALSE&is.na(ex_full_panel$v2x_veracc)==FALSE&is.na(ex_full_panel$num_weak_exprop)==FALSE])))

ols_panel_ac_year<-stargazer(m1_panel_ac_all_p_year, m1_panel_ac_strong_p_year, m1_panel_ac_weak_p_year, 
                        se=list(m1_panel_ac_all_se_p_year, m1_panel_ac_strong_se_p_year, m1_panel_ac_weak_se_p_year),
                        align=TRUE, omit=c('year', 'region',"Constant"), header=FALSE, label="table:ols_ac_year",
                        covariate.labels=c("Vertical Accountability", "Democracy", "GDP per capita", "GDP per capita squared", "Expropriation History"), 
                        title="Vertical Accountability and likelihood of using different types of expropriation, OLS panel with year FEs", font.size="footnotesize", column.sep.width="15pt",
                        add.lines=list(c("Region/Year FE", "Y", "Y", "Y")),dep.var.caption  = "DV: Number of expropriations in given year",
                        dep.var.labels=c("Any expropriation","Overt expropriation","Covert expropriation"),
                        omit.stat=c("f", "ser"),
                        no.space=TRUE,
                        notes = "Robust standard errors clustered at the country level")

write(ols_panel_ac_year, 'R_analysis/PaperOutput/ols_panel_ac_year.tex')




##################################################
###ISDS DATA######################################
################################################

isds<-read.csv('isds_merged.csv')

#creating decade bins
isds$year_bin<-NA
isds$year_bin[isds$year>1979&isds$year<1990]<-"1980s"
isds$year_bin[isds$year>1989&isds$year<2000]<-"1990s"
isds$year_bin[isds$year>1999&isds$year<2010]<-"2000s"
isds$year_bin[isds$year>2009&isds$year<2020]<-"2010s"
isds$year_bin[isds$year>2019]<-"2020s"

isds$type_numeric <-ifelse(isds$type=="direct",1,0)

isds$type_numeric2<-NA
isds$type_numeric2[isds$type=="direct"]<-1
isds$type_numeric2[isds$type=="indirect"]<-0

isds$gdp_pc2<-(isds$gdp_pc)^2

isds$region <-countrycode(isds$Country.Name,origin="country.name",destination='region')

m1_lc_isds<-glm(type_numeric~leg_constraints, data=isds, family='binomial')
cov.m1_lc_isds <- vcovCL(m1_lc_isds, ~country)
robust.se.m1_lc_isds <- sqrt(diag(cov.m1_lc_isds))

m2_lc_isds<-glm(type_numeric~leg_constraints+gdp_pc+gdp_pc2, data=isds, family='binomial')
cov.m2_lc_isds <- vcovCL(m2_lc_isds, ~country)
robust.se.m2_lc_isds <- sqrt(diag(cov.m2_lc_isds))

m3_lc_isds<-glm(type_numeric~leg_constraints+gdp_pc+gdp_pc2+factor(Economic.Sector)+factor(year_bin)+region, data=isds, family='binomial')
cov.m3_lc_isds <- vcovCL(m3_lc_isds, ~country)
robust.se.m3_lc_isds <- sqrt(diag(cov.m3_lc_isds))

m4_lc_isds<-glm(type_numeric~leg_constraints+democracy_p+gdp_pc+gdp_pc2+factor(Economic.Sector)+region+year_bin, data=isds, family='binomial')
cov.m4_lc_isds <- vcovCL(m4_lc_isds, ~country)
robust.se.m4_lc_isds <- sqrt(diag(cov.m4_lc_isds))


conditional_isds_legconstraints_table<-stargazer(m1_lc_isds, m2_lc_isds, m3_lc_isds, m4_lc_isds, se=list(robust.se.m1_lc_isds, robust.se.m2_lc_isds, robust.se.m3_lc_isds, robust.se.m4_lc_isds),
                                                          align=TRUE, omit=c('year_bin', 'region','Constant','Economic.Sector'), header=FALSE, label="table:isds_conditional_expropriation_legconstraints",
                                                 covariate.labels = c("Legislative Constraints","Democracy","GDP per capita","GDP per capita squared"),
                                                 title="Direct expropriation and legislative constraints (ISDS data)", font.size="footnotesize", column.sep.width="0pt",
                                                          add.lines=list(c("Decade/Region FE", "N", "N", "Y",'Y'),c("Sector FE", "N", "N", "Y",'Y')),
                                                 dep.var.labels = "Direct (1) vs. indirect or other (0) breach", no.space=TRUE,
                                                          notes="Robust standard errors clustered at country level")

write(conditional_isds_legconstraints_table[4:length(conditional_isds_legconstraints_table)-1], 'R_analysis/PaperOutput/conditional_isds_lc_table.tex')


#ISDS data with vertacc
m1_ac_isds<-glm(type_numeric~v2x_veracc, data=isds, family='binomial')
cov.m1_ac_isds <- vcovCL(m1_ac_isds, ~country)
robust.se.m1_ac_isds <- sqrt(diag(cov.m1_ac_isds))

m2_ac_isds<-glm(type_numeric~v2x_veracc+gdp_pc+gdp_pc2, data=isds, family='binomial')
cov.m2_ac_isds <- vcovCL(m2_ac_isds, ~country)
robust.se.m2_ac_isds <- sqrt(diag(cov.m2_ac_isds))

m3_ac_isds<-glm(type_numeric~v2x_veracc+gdp_pc+gdp_pc2+factor(Economic.Sector)+factor(year_bin)+region, data=isds, family='binomial')
cov.m3_ac_isds <- vcovCL(m3_ac_isds, ~country)
robust.se.m3_ac_isds <- sqrt(diag(cov.m3_ac_isds))

m4_ac_isds<-glm(type_numeric~v2x_veracc+democracy_p+gdp_pc+gdp_pc2+factor(Economic.Sector)+factor(year_bin)+region, data=isds, family='binomial')
cov.m4_ac_isds <- vcovCL(m4_ac_isds, ~country)
robust.se.m4_ac_isds <- sqrt(diag(cov.m4_ac_isds))


conditional_isds_vertacc_table<-stargazer(m1_ac_isds, m2_ac_isds, m3_ac_isds, m4_ac_isds, se=list(robust.se.m1_ac_isds, robust.se.m2_ac_isds, robust.se.m3_ac_isds, robust.se.m4_ac_isds),
                                                 align=TRUE, omit=c('year_bin', 'region','Constant','Economic.Sector'), header=FALSE, label="table:isds_conditional_expropriation_vertacc",
                                                 covariate.labels = c("Vertical Accountability",'Democracy',"GDP per capita","GDP per capita squared"),
                                                 title="Direct expropriation and vertical accountability (ISDS data)", font.size="footnotesize", column.sep.width="0pt",
                                                 add.lines=list(c("Decade/Region FE", "N", "N", "Y",'Y'),c("Sector FE", "N", "N", "Y",'Y')),
                                          dep.var.labels = "Direct (1) vs. indirect or other (0) breach", no.space=TRUE,
                                                 notes="Robust standard errors clustered at country level")

write(conditional_isds_vertacc_table[4:length(conditional_isds_vertacc_table)-1], 'R_analysis/PaperOutput/conditional_isds_ac_table.tex')


####################################################
#####Poisson vs Negative Binomial#############
####################################################
library("glmmTMB")
library(msme)

poisson_lc_strong <-glm(num_strong_exprop~leg_constraints, family=poisson, data=ex_full_panel)
poisson_lc_any <-glm(num_exprop~leg_constraints, family=poisson, data=ex_full_panel)
poisson_lc_weak <-glm(num_weak_exprop~leg_constraints, family=poisson, data=ex_full_panel)

P__disp(poisson_lc_strong)
P__disp(poisson_lc_any)
P__disp(poisson_lc_weak)

poisson_ac_strong <-glm(num_strong_exprop~v2x_veracc, family=poisson, data=ex_full_panel)
poisson_ac_any <-glm(num_exprop~v2x_veracc, family=poisson, data=ex_full_panel)
poisson_ac_weak <-glm(num_weak_exprop~v2x_veracc, family=poisson, data=ex_full_panel)

P__disp(poisson_ac_strong)
P__disp(poisson_ac_any)
P__disp(poisson_ac_weak)


####Negative binomial leg constraints###
m1_panel_lc_all_p_nb<-glm.nb(num_exprop~leg_constraints+democracy_p+log(lag_gdp_pc)+I(log(lag_gdp_pc)^2)+history+region+factor(year_bin), data=ex_full_panel)
m1_panel_lc_all_se_p_nb<-sqrt(diag(vcovCluster(m1_panel_lc_all_p_nb, ex_full_panel$country[is.na(ex_full_panel$democracy_p)==FALSE&is.na(ex_full_panel$leg_constraints)==FALSE&is.na(ex_full_panel$num_exprop)==FALSE])))

m1_panel_lc_strong_p_nb<-glm.nb(num_strong_exprop~leg_constraints+democracy_p+log(lag_gdp_pc)+I(log(lag_gdp_pc)^2)+history+region+factor(year_bin), data=ex_full_panel)
m1_panel_lc_strong_se_p_nb<-sqrt(diag(vcovCluster(m1_panel_lc_strong_p_nb, ex_full_panel$country[is.na(ex_full_panel$democracy_p)==FALSE&is.na(ex_full_panel$leg_constraints)==FALSE&is.na(ex_full_panel$num_strong_exprop)==FALSE])))

m1_panel_lc_weak_p_nb<-glm.nb(num_weak_exprop~leg_constraints+democracy_p+log(lag_gdp_pc)+I(log(lag_gdp_pc)^2)+history+region+factor(year_bin), data=ex_full_panel)
m1_panel_lc_weak_se_p_nb<-sqrt(diag(vcovCluster(m1_panel_lc_weak_p_nb, ex_full_panel$country[is.na(ex_full_panel$democracy_p)==FALSE&is.na(ex_full_panel$leg_constraints)==FALSE&is.na(ex_full_panel$num_weak_exprop)==FALSE])))

nb_panel_lc<-stargazer(m1_panel_lc_all_p_nb, m1_panel_lc_strong_p_nb, m1_panel_lc_weak_p_nb, 
                        se=list(m1_panel_lc_all_se_p_nb, m1_panel_lc_strong_se_p_nb, m1_panel_lc_weak_se_p_nb),
                        align=TRUE, omit=c('year_bin', 'region','Constant'), header=FALSE, label="table:nb_lc",
                        covariate.labels=c("Legislative Constraints", "Democracy", "GDP per capita", "GDP per capita squared", "Expropriation History"
                        ), title="Legislative constraints and likelihood of using different types of expropriation, negative binomial panel", font.size="footnotesize", column.sep.width="15pt",
                        add.lines=list(c("Region/Year FE", "Y", "Y", "Y")),
                        omit.stat=c("f", "ser"),dep.var.caption  = "DV: Number of expropriations in given year",
                        dep.var.labels=c("Any expropriation","Overt expropriation","Covert expropriation"), no.space=TRUE,
                        notes = "Robust standard errors clustered at the country level")

write(nb_panel_lc, 'R_analysis/PaperOutput/nb_panel_lc.tex')

###############################################################
#######Table 4 Panel Vertical Accountability############
##############################################################

m1_panel_ac_all_p_nb<-glm.nb(num_exprop~v2x_veracc+democracy_p+log(lag_gdp_pc)+I(log(lag_gdp_pc)^2)+history+region+year_bin, data=ex_full_panel)
m1_panel_ac_all_se_p_nb<-sqrt(diag(vcovCluster(m1_panel_ac_all_p_nb, ex_full_panel$country[is.na(ex_full_panel$democracy_p)==FALSE&is.na(ex_full_panel$v2x_veracc)==FALSE&is.na(ex_full_panel$num_exprop)==FALSE])))

m1_panel_ac_strong_p_nb<-glm.nb(num_strong_exprop~v2x_veracc+democracy_p+log(lag_gdp_pc)+I(log(lag_gdp_pc)^2)+history+region+year_bin, data=ex_full_panel)
m1_panel_ac_strong_se_p_nb<-sqrt(diag(vcovCluster(m1_panel_ac_strong_p_nb, ex_full_panel$country[is.na(ex_full_panel$democracy_p)==FALSE&is.na(ex_full_panel$v2x_veracc)==FALSE&is.na(ex_full_panel$num_strong_exprop)==FALSE])))

m1_panel_ac_weak_p_nb<-glm.nb(num_weak_exprop~v2x_veracc+democracy_p+log(lag_gdp_pc)+I(log(lag_gdp_pc)^2)+history+region+year_bin, data=ex_full_panel)
m1_panel_ac_weak_se_p_nb<-sqrt(diag(vcovCluster(m1_panel_ac_weak_p_nb, ex_full_panel$country[is.na(ex_full_panel$democracy_p)==FALSE&is.na(ex_full_panel$v2x_veracc)==FALSE&is.na(ex_full_panel$num_weak_exprop)==FALSE])))

panel_ac_nb<-stargazer(m1_panel_ac_all_p_nb, m1_panel_ac_strong_p_nb, m1_panel_ac_weak_p_nb, 
                        se=list(m1_panel_ac_all_se_p_nb, m1_panel_ac_strong_se_p_nb, m1_panel_ac_weak_se_p_nb),
                        align=TRUE, omit=c('year_bin', 'region',"Constant"), header=FALSE, label="table:nb_ac",
                        covariate.labels=c("Vertical Accountability", "Democracy", "GDP per capita", "GDP per capita squared", "Expropriation History"), 
                        title="Vertical Accountability and likelihood of using different types of expropriation, negative binomial panel", font.size="footnotesize", column.sep.width="15pt",
                        add.lines=list(c("Region/Decade FE", "Y", "Y", "Y")),dep.var.caption  = "DV: Number of expropriations in given year",
                        dep.var.labels=c("Any expropriation","Overt expropriation","Covert expropriation"),
                        omit.stat=c("f", "ser"),
                        no.space=TRUE,
                        notes = "Robust standard errors clustered at the country level")

write(panel_ac_nb, 'R_analysis/PaperOutput/nb_panel_ac_nb.tex')





#########Conditional analysis Vert Acc############
m1_ac_socialism<-glm(strong_exprop~v2x_veracc+v2csanmvch_6, data=exprop_dem_gdp, family='binomial')
cov.m1_ac_socialism_cluster <- vcovCL(m1_ac_socialism, ~country)
robust.se.m1_ac_socialism_cluster <- sqrt(diag(cov.m1_ac_socialism_cluster))

m2_ac_socialism<-glm(strong_exprop~v2x_veracc+democracy_p+ll_gdp_pc+ll_gdp_pc2+factor(sector2)+v2csanmvch_6, data=exprop_dem_gdp, family='binomial')
cov.m2_ac_socialism_cluster <- vcovCL(m2_ac_socialism, ~country)
robust.se.m2_ac_socialism_cluster <- sqrt(diag(cov.m2_ac_socialism_cluster))

m3_ac_socialism<-glm(strong_exprop~v2x_veracc+ll_gdp_pc+ll_gdp_pc2+factor(sector2)+region+factor(year_bin)+v2csanmvch_6, data=exprop_dem_gdp, family='binomial')
cov.m3_ac_socialism_cluster <- vcovCL(m3_ac_socialism, ~country)
robust.se.m3_ac_socialism_cluster <- sqrt(diag(cov.m3_ac_socialism_cluster))

m4_ac_socialism<-glm(strong_exprop~v2x_veracc+democracy_p+ll_gdp_pc+ll_gdp_pc2+factor(sector2)+region+factor(year_bin)+v2csanmvch_6, data=exprop_dem_gdp, family='binomial')
cov.m4_ac_socialism_cluster <- vcovCL(m4_ac_socialism, ~country)
robust.se.m4_ac_socialism_cluster <- sqrt(diag(cov.m4_ac_socialism_cluster))

conditional_expropriation_ac_socialism_table_cluster<-stargazer(m1_ac_socialism, m2_ac_socialism, m3_ac_socialism, m4_ac_socialism, se=list(robust.se.m1_ac_socialism_cluster, robust.se.m2_ac_socialism_cluster, robust.se.m3_ac_socialism_cluster, robust.se.m4_ac_socialism_cluster),
                                                          align=TRUE, omit=c('year_bin', 'region','Constant'), header=FALSE, label="table:conditional_expropriation_ac_socialism",
                                                          covariate.labels=c("Vertical Accountability", "Democracy", "GDP per capita", "GDP per capita squared", "Extractive sector",
                                                                             "Financial sector", "Manufacturing sector", "Services sector", "Utilities sector", "Socialism"
                                                          ), title="Vertical Accountability and Propensity to Use Overt Expropriation, controlling for socialism", font.size="footnotesize", column.sep.width="0pt",
                                                          add.lines=list(c("Decade/Region FE", "N", "N", "Y","Y")),
                                                          dep.var.labels="Use of overt (1) vs. covert (0) expropriation", no.space=TRUE,
                                                          notes="Robust standard errors clustered at country level")
write(conditional_expropriation_ac_socialism_table_cluster, 'R_analysis/PaperOutput/conditional_expropriation_ac_socialism_table_cluster.tex')


####Panel Analysis, OLS Vert acc, controlling for socialism####

m1_socialism_panel_all_socialism_ac<-lm(num_exprop~ v2x_veracc+democracy_p +v2csanmvch_6 +log(lag_gdp_pc)+I(log(lag_gdp_pc)^2)+history+region+year_bin, data=ex_full_panel)
m1_socialism_panel_all_se_socialism_ac<-sqrt(diag(vcovCluster(m1_socialism_panel_all_socialism_ac, ex_full_panel$country[is.na(ex_full_panel$v2x_veracc)==FALSE&is.na(ex_full_panel$v2csanmvch_6)==F&is.na(ex_full_panel$num_exprop)==FALSE&is.na(ex_full_panel$democracy_p)==FALSE])))

m1_socialism_panel_strong_socialism_ac<-lm(num_strong_exprop~ v2x_veracc+democracy_p +v2csanmvch_6 +log(lag_gdp_pc)+I(log(lag_gdp_pc)^2)+history+region+year_bin, data=ex_full_panel)
m1_socialism_panel_strong_se_socialism_ac<-sqrt(diag(vcovCluster(m1_socialism_panel_strong_socialism_ac, ex_full_panel$country[is.na(ex_full_panel$v2x_veracc)==FALSE&is.na(ex_full_panel$v2csanmvch_6)==F&is.na(ex_full_panel$num_strong_exprop)==FALSE&is.na(ex_full_panel$democracy_p)==FALSE])))

m1_socialism_panel_weak_socialism_ac<-lm(num_weak_exprop~ v2x_veracc+democracy_p + v2csanmvch_6 +log(lag_gdp_pc)+I(log(lag_gdp_pc)^2)+history+region+year_bin, data=ex_full_panel)
m1_socialism_panel_weak_se_socialism_ac<-sqrt(diag(vcovCluster(m1_socialism_panel_weak_socialism_ac, ex_full_panel$country[is.na(ex_full_panel$v2x_veracc)==FALSE&is.na(ex_full_panel$v2csanmvch_6)==F&is.na(ex_full_panel$num_weak_exprop)==FALSE&is.na(ex_full_panel$democracy_p)==FALSE])))

ols_socialism_panel_ac<-stargazer(m1_socialism_panel_all_socialism_ac, m1_socialism_panel_strong_socialism_ac, m1_socialism_panel_weak_socialism_ac, 
                            se=list(m1_socialism_panel_all_se_socialism_ac, m1_socialism_panel_strong_se_socialism, m1_socialism_panel_weak_se_socialism),
                            align=TRUE, omit=c('year_bin', 'region','Constant'), header=FALSE, label="table:ols_socialism_panel_ac",
                            covariate.labels=c("Vertical Accountability", 'Democracy', 'Socialism', "GDP per capita", "GDP per capita squared", "Expropriation History" 
                            ), title="Vertical Accountability and expropriation type, panel using OLS, controlling for socialism", font.size="footnotesize", column.sep.width="15pt",
                            add.lines=list(c("Region/Decade FE", "Y", "Y", "Y")),
                            omit.stat=c("f", "ser"),dep.var.caption  = "DV: Number of expropriations in given year",
                            dep.var.labels=c("Any expropriation","Overt expropriation","Covert expropriation"), no.space=TRUE,
                            notes = "Robust standard errors clustered at the country level")

write(ols_socialism_panel_ac, 'R_analysis/PaperOutput/ols_socialism_panel_ac.tex')



#####multinomial logit vert acc, controlling for socialism
multinom_fullcontrols_ac_socialism<-multinom_function(ex_full_panel[c('exprop_numeric', 'exprop_numeric_b1', 'v2x_veracc','year_bin','democracy_p', 'v2csanmvch_6',
                                                                'll_gdp_pc', 'll_gdp_pc2', 'history', 'region', 'country_num')], 'exprop_numeric', 'exprop_numeric_b1', iterations)
ggsave('R_analysis/PaperOutput/multinom_fullcontrols_ac_socialism_plot.pdf', plot=multinom_plot(multinom_fullcontrols_ac_socialism), height=5, width=5.25)







##########################################################
#####################Foreign audience costs################
##########################################################
m1_fc<-glm(strong_exprop~fdi_stock_perc, data=exprop_dem_gdp, family='binomial')
cov.m1_fc_cluster <- vcovCL(m1_fc, ~country)
robust.se.m1_fc_cluster <- sqrt(diag(cov.m1_fc_cluster))

m2_fc<-glm(strong_exprop~fdi_stock_perc+democracy_p+ll_gdp_pc+ll_gdp_pc2+factor(sector2), data=exprop_dem_gdp, family='binomial')
cov.m2_fc_cluster <- vcovCL(m2_fc, ~country)
robust.se.m2_fc_cluster <- sqrt(diag(cov.m2_fc_cluster))

m3_fc<-glm(strong_exprop~fdi_stock_perc+ll_gdp_pc+ll_gdp_pc2+factor(sector2)+region+factor(year_bin), data=exprop_dem_gdp, family='binomial')
cov.m3_fc_cluster <- vcovCL(m3_fc, ~country)
robust.se.m3_fc_cluster <- sqrt(diag(cov.m3_fc_cluster))

m4_fc<-glm(strong_exprop~fdi_stock_perc+democracy_p+ll_gdp_pc+ll_gdp_pc2+factor(sector2)+region+factor(year_bin), data=exprop_dem_gdp, family='binomial')
cov.m4_fc_cluster <- vcovCL(m4_fc, ~country)
robust.se.m4_fc_cluster <- sqrt(diag(cov.m4_fc_cluster))


clustered_conditional_expropriation_foreign_table<-stargazer(m1_fc, m2_fc, m3_fc, m4_fc, se=list(robust.se.m1_fc_cluster, robust.se.m2_fc_cluster, robust.se.m3_fc_cluster, robust.se.m4_fc_cluster),
                                                             align=TRUE, omit=c('region','year_bin','Constant'), header=FALSE, label="table:conditional_expropriation_fdi_stock",
                                                             covariate.labels=c("Lagged FDI Stock as percent GDP", "Democracy", "GDP per capita", "GDP per capita squared", "Extractive sector",
                                                                                "Financial sector", "Manufacturing sector", "Services sector", "Utilities sector"), title="Overt expropriation and Foreign Audience Costs, measured by FDI Stock as percent GDP", font.size="footnotesize", column.sep.width="0pt",
                                                             add.lines=list(c("Decade/Region FE", "N", "N", "Y","Y")),
                                                             dep.var.labels = "Use of overt (1) vs. covert (0) expropriation", no.space=TRUE,
                                                             notes="Robust standard errors clustered at country level")
write(clustered_conditional_expropriation_foreign_table[4:length(clustered_conditional_expropriation_foreign_table)-1], 'R_analysis/PaperOutput/conditional_expropriation_foreign_table.tex')

m1_flow<-glm(strong_exprop~fdi_flows_perc, data=exprop_dem_gdp, family='binomial')
cov.m1_flow_cluster <- vcovCL(m1_flow, ~country)
robust.se.m1_flow_cluster <- sqrt(diag(cov.m1_flow_cluster))

m2_flow<-glm(strong_exprop~fdi_flows_perc+democracy_p+ll_gdp_pc+ll_gdp_pc2+factor(sector2), data=exprop_dem_gdp, family='binomial')
cov.m2_flow_cluster <- vcovCL(m2_flow, ~country)
robust.se.m2_flow_cluster <- sqrt(diag(cov.m2_flow_cluster))

m3_flow<-glm(strong_exprop~fdi_flows_perc+ll_gdp_pc+ll_gdp_pc2+factor(sector2)+region+factor(year_bin), data=exprop_dem_gdp, family='binomial')
cov.m3_flow_cluster <- vcovCL(m3_flow, ~country)
robust.se.m3_flow_cluster <- sqrt(diag(cov.m3_flow_cluster))

m4_flow<-glm(strong_exprop~fdi_flows_perc+democracy_p+ll_gdp_pc+ll_gdp_pc2+factor(sector2)+region+factor(year_bin), data=exprop_dem_gdp, family='binomial')
cov.m4_flow_cluster <- vcovCL(m4_flow, ~country)
robust.se.m4_flow_cluster <- sqrt(diag(cov.m4_flow_cluster))


clustered_conditional_expropriation_flow_table<-stargazer(m1_flow, m2_flow, m3_flow, m4_flow, se=list(robust.se.m1_flow_cluster, robust.se.m2_flow_cluster, robust.se.m3_flow_cluster, robust.se.m4_flow_cluster),
                                                          align=TRUE, omit=c('region','year_bin','Constant'), header=FALSE, label="table:conditional_expropriation_fdi_flo",
                                                          covariate.labels=c("Lagged FDI Flows as  percent GDP", "Democracy", "GDP per capita", "GDP per capita squared", "Extractive sector",
                                                                             "Financial sector", "Manufacturing sector", "Services sector", "Utilities sector"), title="Overt expropriation and Foreign Audience Costs, measured by FDI Flows as percent GDP", font.size="footnotesize", column.sep.width="0pt",
                                                          add.lines=list(c("Decade/Region FE", "N", "N", "Y","Y")),
                                                          dep.var.labels = "Use of overt (1) vs. covert (0) expropriation", no.space=TRUE,
                                                          notes="Robust standard errors clustered at country level")
write(clustered_conditional_expropriation_flow_table[4:length(clustered_conditional_expropriation_flow_table)-1], 'R_analysis/PaperOutput/conditional_expropriation_flow_table.tex')








